Class: Gosu::Image
- Inherits:
-
Object
- Object
- Gosu::Image
- Defined in:
- rdoc/gosu.rb
Overview
Provides functionality for drawing rectangular images.
Instance Attribute Summary collapse
-
#height ⇒ Integer
readonly
The image’s height, in pixels.
-
#width ⇒ Integer
readonly
The image’s width, in pixels.
Creating and loading images collapse
-
.from_blob(width, height, rgba = "\0\0\0\0" * (width * height)) ⇒ Object
Creates a new image with the given dimensions and RGBA pixel data.
-
.from_markup(markup, line_height, options = {}) ⇒ Object
Like #from_text, but supports the following markup tags: ‘bold`, `italic`, `<c=rrggbb>colors</c>`.
-
.from_text(text, line_height, options = {}) ⇒ Gosu::Image
Creates a reusable image from one or more lines of text.
-
.load_tiles(source, tile_width, tile_height, options = {}) ⇒ Array<Gosu::Image>
Loads an image from a file or an RMagick image, then divides the image into an array of equal-sized tiles.
-
#initialize(source, options = {}) ⇒ Image
constructor
Loads an image from a file or an RMagick image.
-
#subimage(left, top, width, height) ⇒ Image?
Returns an image that is a smaller, rectangular view of this Image.
Drawing an image collapse
-
#draw(x, y, z = 0, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ void
Draws the image with its top left corner at (x, y).
-
#draw_as_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode = :default) ⇒ void
Draws the image as an arbitrary quad.
-
#draw_rot(x, y, z = 0, angle = 0, center_x = 0.5, center_y = 0.5, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ void
Draws the image rotated, with its rotational center at (x, y).
Instance Method Summary collapse
-
#gl_tex_info ⇒ Gosu::GLTexInfo?
Returns an object that holds information about the underlying OpenGL texture and UV coordinates of the image.
-
#insert(source, x, y) ⇒ void
Overwrites part of the image with the contents of another.
-
#save(filename) ⇒ void
Saves the image to a file.
-
#to_blob ⇒ String
Returns the associated texture contents as binary string of packed RGBA values, useful for use with RMagick (Magick::Image.from_blob).
Constructor Details
#initialize(source, options = {}) ⇒ Image #initialize(window, source, tileable = false) ⇒ Image #initialize(window, source, tileable, left, top, width, height) ⇒ Image
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.)
384 |
# File 'rdoc/gosu.rb', line 384 def initialize(source, = {}); end |
Instance Attribute Details
#height ⇒ Integer (readonly)
Returns the image’s height, in pixels.
360 361 362 |
# File 'rdoc/gosu.rb', line 360 def height @height end |
#width ⇒ Integer (readonly)
Returns the image’s width, in pixels.
356 357 358 |
# File 'rdoc/gosu.rb', line 356 def width @width end |
Class Method Details
.from_blob(width, height, rgba = "\0\0\0\0" * (width * height)) ⇒ Object
Creates a new image with the given dimensions and RGBA pixel data.
392 |
# File 'rdoc/gosu.rb', line 392 def self.from_blob(width, height, rgba = "\0\0\0\0" * (width * height)); end |
.from_markup(markup, line_height, options = {}) ⇒ Object
Like #from_text, but supports the following markup tags: ‘bold`, `italic`, `<c=rrggbb>colors</c>`.
424 |
# File 'rdoc/gosu.rb', line 424 def self.from_markup(markup, line_height, = {}); 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
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.)
420 |
# File 'rdoc/gosu.rb', line 420 def self.from_text(text, line_height, = {}); end |
.load_tiles(source, tile_width, tile_height, options = {}) ⇒ Array<Gosu::Image> .load_tiles(window, source, tile_width, tile_height, tileable) ⇒ Array<Gosu::Image>
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.)
445 |
# File 'rdoc/gosu.rb', line 445 def self.load_tiles(source, tile_width, tile_height, = {}); end |
Instance Method Details
#draw(x, y, z = 0, 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).
479 |
# File 'rdoc/gosu.rb', line 479 def draw(x, y, z=0, 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.
506 |
# File 'rdoc/gosu.rb', line 506 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 = 0, angle = 0, 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).
493 |
# File 'rdoc/gosu.rb', line 493 def draw_rot(x, y, z=0, angle=0, center_x=0.5, center_y=0.5, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end |
#gl_tex_info ⇒ Gosu::GLTexInfo?
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.
518 |
# File 'rdoc/gosu.rb', line 518 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.
541 |
# File 'rdoc/gosu.rb', line 541 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.
550 |
# File 'rdoc/gosu.rb', line 550 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.
457 |
# File 'rdoc/gosu.rb', line 457 def subimage(left, top, width, height); end |
#to_blob ⇒ String
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
530 |
# File 'rdoc/gosu.rb', line 530 def to_blob; end |