Class: Gosu::Image

Inherits:
Object
  • Object
show all
Defined in:
rdoc/gosu.rb

Overview

Provides functionality for drawing rectangular images.

Instance Attribute Summary collapse

Creating and loading images collapse

Drawing an image collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Image #initialize(window, source, tileable = false) ⇒ Image #initialize(window, source, tileable, left, top, width, height) ⇒ Image

Note:

For Windows Bitmap (BMP) images, magenta (FF00FF, often called “magic pink” in this context) is treated as a chroma key and all pixels of that color are automatically rendered fully transparent.

Loads an image from a file or an RMagick image.

(Passing a Window reference is not necessary anymore, please use the first overload from now on.)

Options Hash (options):

  • :tileable (true, false) — default: false

    if true, the Image will not have soft edges when scaled

  • :retro (true, false) — default: false

    if true, the image will not be interpolated when it is scaled up or down. When :retro it set, :tileable has no effect.

  • :rect (Array) — default: [0, 0, image_width, image_height]

    the source rectangle in the image

See Also:


349
# File 'rdoc/gosu.rb', line 349

def initialize(source, options = {}); end

Instance Attribute Details

#heightInteger (readonly)


325
326
327
# File 'rdoc/gosu.rb', line 325

def height
  @height
end

#widthInteger (readonly)


321
322
323
# File 'rdoc/gosu.rb', line 321

def width
  @width
end

Class Method Details

.from_markup(markup, line_height, options = {}) ⇒ Object

Like #from_text, but supports the following markup tags: `bold`, `italic`, `<c=rrggbb>colors</c>`.


381
# File 'rdoc/gosu.rb', line 381

def self.from_markup(markup, line_height, options = {}); end

.from_text(text, line_height, options = {}) ⇒ Gosu::Image .from_text(window, text, font_name, line_height) ⇒ Gosu::Image .from_text(window, text, font_name, line_height, line_spacing, width, align) ⇒ Gosu::Image

Note:

The text is always rendered in white. To draw it in a different color, use the color parameter of #draw, et al.

Creates a reusable image from one or more lines of text.

(Passing a Window reference is not necessary anymore, please use the first overload from now on.)

Options Hash (options):

  • :font (String) — default: Gosu::default_font_name

    the name of a system font, or a path to a TrueType Font (TTF) file. A path must contain at least one '/' character to distinguish it from a system font.

  • :bold (bool) — default: false
  • :italic (bool) — default: false
  • :underline (bool) — default: false
  • :width (Integer)

    the width of the image, in pixels. Long lines will be automatically wrapped around to avoid overflow, but overlong words will be truncated. If this option is omitted, lines will not be wrapped, and :align and :spacing will be ignored as well.

  • :spacing (Integer) — default: 0

    the spacing between lines, in pixels.

  • :align (:left, :right, :center, :justify) — default: :left

    the text alignment.

  • :retro (true, false) — default: false

    if true, the image will not be interpolated when it is scaled up or down.

See Also:


377
# File 'rdoc/gosu.rb', line 377

def self.from_text(text, line_height, options = {}); end

.load_tiles(source, tile_width, tile_height, options = {}) ⇒ Array<Gosu::Image> .load_tiles(window, source, tile_width, tile_height, tileable) ⇒ Array<Gosu::Image>

Note:

For Windows Bitmap (BMP) images, magenta (FF00FF, often called “magic pink” in this context) is treated as a chroma key and all pixels of that color are automatically rendered fully transparent.

Loads an image from a file or an RMagick image, then divides the image into an array of equal-sized tiles.

(Passing a Window reference is not necessary anymore, please use the first overload from now on.)

Options Hash (options):

  • :tileable (true, false) — default: false

    if true, the Image will not have soft edges when scaled

  • :retro (true, false) — default: false

    if true, the image will not be interpolated when it is scaled up or down. When :retro it set, :tileable has no effect.

See Also:


402
# File 'rdoc/gosu.rb', line 402

def self.load_tiles(source, tile_width, tile_height, options = {}); end

Instance Method Details

#draw(x, y, z, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ void

This method returns an undefined value.

Draws the image with its top left corner at (x, y).


436
# File 'rdoc/gosu.rb', line 436

def draw(x, y, z, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end

#draw_as_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode = :default) ⇒ void

This method returns an undefined value.

Draws the image as an arbitrary quad. This method can be used for advanced non-rectangular drawing techniques, e.g., faking perspective or isometric projection.


463
# File 'rdoc/gosu.rb', line 463

def draw_as_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode=:default); end

#draw_rot(x, y, z, angle, center_x = 0.5, center_y = 0.5, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ void

This method returns an undefined value.

Draws the image rotated, with its rotational center at (x, y).


450
# File 'rdoc/gosu.rb', line 450

def draw_rot(x, y, z, angle, center_x=0.5, center_y=0.5, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end

#gl_tex_infoGosu::GLTexInfo?

Note:

Some images may be too large to fit on a single texture; this method returns nil in those cases.

Returns an object that holds information about the underlying OpenGL texture and UV coordinates of the image.

See Also:


475
# File 'rdoc/gosu.rb', line 475

def gl_tex_info; end

#insert(source, x, y) ⇒ void

This method returns an undefined value.

Overwrites part of the image with the contents of another. If the source image is partially out of bounds, it will be clipped to fit.

This can be used to e.g. overwrite parts of a landscape.


498
# File 'rdoc/gosu.rb', line 498

def insert(source, x, y); end

#save(filename) ⇒ void

This method returns an undefined value.

Saves the image to a file. The file format is determined from the file extension.

Useful for, e.g., pre-rendering text on a development machine where the necessary fonts are known to be available.


507
# File 'rdoc/gosu.rb', line 507

def save(filename); end

#subimage(left, top, width, height) ⇒ Image?

Returns an image that is a smaller, rectangular view of this Gosu::Image.

This is a very fast operation, and no new textures will be allocated. If you update this Gosu::Image or the #subimage using #insert, the other Gosu::Image will be affected as well.

Caveats:

  • If you stretch or rotate a #subimage, the pixels adjacent to it might bleed into it, as Gosu does not manage the 'tileability' of subimages.


414
# File 'rdoc/gosu.rb', line 414

def subimage(left, top, width, height); end

#to_blobString

Returns the associated texture contents as binary string of packed RGBA values, useful for use with RMagick (Magick::Image.from_blob).

magick_image = Magick::Image.from_blob(image.to_blob) {
  self.format = "RGBA"
  self.size = "#{image.width}x#{image.height}"
  self.depth = 8
}.first

487
# File 'rdoc/gosu.rb', line 487

def to_blob; end