Class: Ruby2D::Image
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
Instance Method Summary collapse
- #draw(opts = {}) ⇒ Object
-
#initialize(path, opts = {}) ⇒ Image
constructor
A new instance of Image.
Methods included from Renderable
Constructor Details
#initialize(path, opts = {}) ⇒ Image
Returns a new instance of Image.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby2d/image.rb', line 18 def initialize(path, opts = {}) @path = path @texture = Texture.new(*Image.load_image(@path)) @width = opts[:width] || @texture.width @height = opts[:height] || @texture.height @x = opts[:x] || 0 @y = opts[:y] || 0 @z = opts[:z] || 0 @rotate = opts[:rotate] || 0 self.color = opts[:color] || 'white' self.color.opacity = opts[:opacity] if opts[:opacity] unless opts[:show] == false then add end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def data @data end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def height @height end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/ruby2d/image.rb', line 7 def path @path end |
#rotate ⇒ Object
Returns the value of attribute rotate.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def rotate @rotate end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/ruby2d/image.rb', line 8 def y @y end |
Class Method Details
.load_image(path) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ruby2d/image.rb', line 10 def self.load_image(path) unless File.exist? path raise Error, "Cannot find image file `#{path}`" end ext_load_image(path) end |
Instance Method Details
#draw(opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby2d/image.rb', line 35 def draw(opts = {}) Window.render_ready_check opts[:width] = opts[:width] || @width opts[:height] = opts[:height] || @height opts[:rotate] = opts[:rotate] || @rotate unless opts[:color] opts[:color] = [1.0, 1.0, 1.0, 1.0] end render(x: opts[:x], y: opts[:y], width: opts[:width], height: opts[:height], color: Color.new(opts[:color]), rotate: opts[:rotate]) end |