Class: Gosu::Image
- Inherits:
-
Object
- Object
- Gosu::Image
- Defined in:
- reference/gosu.rb
Overview
Provides functionality for drawing rectangular images.
Instance Attribute Summary (collapse)
-
- (Object) height
readonly
Returns the value of attribute height.
-
- (Object) width
readonly
Returns the value of attribute width.
Class Method Summary (collapse)
-
+ (Object) from_text(window, text, font_name, font_height, line_spacing, max_width, align)
Creates an Image that is filled with the text given to the function.
-
+ (Object) load_tiles(window, filename_or_rmagick_image, tile_width, tile_height, tileable)
Convenience function that splits an image file into an array of small rectangles and creates images from these.
Instance Method Summary (collapse)
-
- (Object) draw(x, y, z, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default)
Draws the image so its upper left corner is at (x; y).
-
- (Object) draw_as_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode = :default)
Like Window#draw_quad, but with this texture instead of colors.
-
- (Object) draw_rot(x, y, z, angle, center_x = 0.5, center_y = 0.5, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default)
center_x: Relative horizontal position of the rotation center on the image. -
- (Object) gl_tex_info
See examples/OpenGLIntegration.rb.
-
- (Image) initialize(window, filename_or_rmagick_image, tileable, src_x, src_y, src_width, src_height)
constructor
Loads an image from a given filename that can be drawn onto the given window.
-
- (Object) insert(filename_or_rmagick_image, x, y)
Overwrites all or parts of the Image.
-
- (Object) save(filename)
Saves the texture contents as an image file.
-
- (Object) to_blob
Returns the associated texture contents as binary string of RGBA values.
Constructor Details
- (Image) initialize(window, filename_or_rmagick_image, tileable, src_x, src_y, src_width, src_height)
Loads an image from a given filename that can be drawn onto the given window. See the Gosu wiki for a list of supported formats.
A color key of #ff00ff is automatically applied to BMP type images.
This constructor only loads a sub-rectangle of the given file. Because every call of this constructor will open the image again, it is preferable to use Image#load_tiles when possible.
231 |
# File 'reference/gosu.rb', line 231 def initialize(window, filename_or_rmagick_image, tileable, src_x, src_y, src_width, src_height) end |
Instance Attribute Details
- (Object) height (readonly)
Returns the value of attribute height
225 226 227 |
# File 'reference/gosu.rb', line 225 def height @height end |
- (Object) width (readonly)
Returns the value of attribute width
225 226 227 |
# File 'reference/gosu.rb', line 225 def width @width end |
Class Method Details
+ (Object) from_text(window, text, font_name, font_height, line_spacing, max_width, align)
Creates an Image that is filled with the text given to the function.
The text may contain line breaks.
The text is always rendered in white. If you want to draw it in a different color, just modulate it by the target color.
| font_name: | Name of a system font, or a filename to a TTF file (must contain ’/’). |
| font_height: | Height of the font in pixels. |
| line_spacing: | Spacing between two lines of text in pixels. |
| max_width: | Width of the bitmap that will be returned. Text will be split into multiple lines to avoid drawing over the right border. When a single word is too long, it will be truncated. |
| align: | One of :left, :right, :center or :justify. |
260 |
# File 'reference/gosu.rb', line 260 def self.from_text(window, text, font_name, font_height, line_spacing, max_width, align) end |
+ (Object) load_tiles(window, filename_or_rmagick_image, tile_width, tile_height, tileable)
Convenience function that splits an image file into an array of small rectangles and creates images from these. Returns the Array containing Image instances.
A color key of #ff00ff is automatically applied to BMP type images.
| tile_width: | If positive, specifies the width of one tile in pixels. If negative, the bitmap is divided into -tile_width rows. |
| tile_height: | See tile_width. |
282 |
# File 'reference/gosu.rb', line 282 def self.load_tiles(window, filename_or_rmagick_image, tile_width, tile_height, tileable) end |
Instance Method Details
- (Object) draw(x, y, z, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default)
Draws the image so its upper left corner is at (x; y).
244 |
# File 'reference/gosu.rb', line 244 def draw(x, y, z, factor_x=1, factor_y=1, color=0xffffffff, mode=:default) end |
- (Object) draw_as_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode = :default)
Like Window#draw_quad, but with this texture instead of colors. Can be used to implement advanced, non-rectangular drawing techniques and takes four points and the modulation color at each of them. The points can be in clockwise order, or in a Z shape, starting at the top left.
252 |
# File 'reference/gosu.rb', line 252 def draw_as_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode=:default) end |
- (Object) draw_rot(x, y, z, angle, center_x = 0.5, center_y = 0.5, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default)
| center_x: | Relative horizontal position of the rotation center on the image. 0 is the left border, 1 is the right border, 0.5 is the center (and default) |
| center_y: | See center_x. |
248 |
# File 'reference/gosu.rb', line 248 def draw_rot(x, y, z, angle, center_x=0.5, center_y=0.5, factor_x=1, factor_y=1, color=0xffffffff, mode=:default) end |
- (Object) gl_tex_info
See examples/OpenGLIntegration.rb.
285 |
# File 'reference/gosu.rb', line 285 def gl_tex_info; end |
- (Object) insert(filename_or_rmagick_image, x, y)
Overwrites all or parts of the Image. x and y can be negative or otherwise out of bounds, the incoming image data is clipped to the current image size. This can be used to e.g. overwrite parts of a landscape.
294 |
# File 'reference/gosu.rb', line 294 def insert(filename_or_rmagick_image, x, y) end |
- (Object) save(filename)
Saves the texture contents as an image file. Useful, for example, to pre-render text on a development machine with proper fonts installed. The file format is determined from the file extension. See the Gosu wiki for a list of portably supported formats.
300 |
# File 'reference/gosu.rb', line 300 def save(filename) end |
- (Object) to_blob
Returns the associated texture contents as binary string of RGBA values. Useful for use with RMagick (Magick::Image.from_blob).
289 |
# File 'reference/gosu.rb', line 289 def to_blob; end |