Class: Ruby2D::Image
Overview
Images in many popular formats can be drawn in the window. To draw an image in the window, use the following, providing the image file path: Image.new(‘star.png’)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#height ⇒ Object
Returns the value of attribute height.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#rotate ⇒ Object
Returns the value of attribute rotate.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from Renderable
Class Method Summary collapse
-
.load_image_as_texture(path, atlas:) ⇒ Texture
Load an image
path
and return a Texture, using a pixmap atlas if provided.
Instance Method Summary collapse
- #draw(x: 0, y: 0, width: nil, height: nil, rotate: 0, color: nil, colour: nil) ⇒ Object
-
#initialize(path, atlas: nil, width: nil, height: nil, x: 0, y: 0, z: 0, rotate: 0, color: nil, colour: nil, opacity: nil, show: true) ⇒ Image
constructor
Create an Image.
Methods included from Renderable
Constructor Details
#initialize(path, atlas: nil, width: nil, height: nil, x: 0, y: 0, z: 0, rotate: 0, color: nil, colour: nil, opacity: nil, show: true) ⇒ Image
Create an Image
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby2d/image.rb', line 39 def initialize(path, atlas: nil, width: nil, height: nil, x: 0, y: 0, z: 0, rotate: 0, color: nil, colour: nil, opacity: nil, show: true) @path = path.to_s # Consider input pixmap atlas if supplied to load image file @texture = Image.load_image_as_texture @path, atlas: atlas @width = width || @texture.width @height = height || @texture.height @x = x @y = y @z = z @rotate = rotate self.color = color || colour || 'white' self.color.opacity = opacity unless opacity.nil? add if show end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/ruby2d/image.rb', line 13 def data @data end |
#height ⇒ Object
Returns the value of attribute height.
13 14 15 |
# File 'lib/ruby2d/image.rb', line 13 def height @height end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/ruby2d/image.rb', line 12 def path @path end |
#rotate ⇒ Object
Returns the value of attribute rotate.
13 14 15 |
# File 'lib/ruby2d/image.rb', line 13 def rotate @rotate end |
#width ⇒ Object
Returns the value of attribute width.
13 14 15 |
# File 'lib/ruby2d/image.rb', line 13 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
13 14 15 |
# File 'lib/ruby2d/image.rb', line 13 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
13 14 15 |
# File 'lib/ruby2d/image.rb', line 13 def y @y end |
Class Method Details
.load_image_as_texture(path, atlas:) ⇒ Texture
Load an image path
and return a Texture, using a pixmap atlas if provided
19 20 21 22 23 24 25 26 |
# File 'lib/ruby2d/image.rb', line 19 def self.load_image_as_texture(path, atlas:) pixmap = if atlas atlas.load_and_keep_image(path, as: path) else Pixmap.new path end pixmap.texture end |
Instance Method Details
#draw(x: 0, y: 0, width: nil, height: nil, rotate: 0, color: nil, colour: nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/ruby2d/image.rb', line 60 def draw(x: 0, y: 0, width: nil, height: nil, rotate: 0, color: nil, colour: nil) Window.render_ready_check render(x: x, y: y, width: width || @width, height: height || @height, color: Color.new(color || colour || 'white'), rotate: rotate || @rotate) end |