Class: DXRuby::Tiled::ImageLayer
- Inherits:
-
Object
- Object
- DXRuby::Tiled::ImageLayer
- Defined in:
- lib/dxruby_tiled/imagelayer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#fixed ⇒ Object
Returns the value of attribute fixed.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#offset_x ⇒ Object
Returns the value of attribute offset_x.
-
#offset_y ⇒ Object
Returns the value of attribute offset_y.
-
#opacity ⇒ Object
Returns the value of attribute opacity.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
- #draw(x, y, target = DXRuby::Window) ⇒ Object
-
#initialize(data, map) ⇒ ImageLayer
constructor
A new instance of ImageLayer.
Constructor Details
#initialize(data, map) ⇒ ImageLayer
Returns a new instance of ImageLayer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 7 def initialize(data, map) @original_data = data @map = map @name = data[:name] @opacity = data[:opacity] || 1.0 @visible = data[:visible] != false @offset_x = data[:offsetx] || 0 @offset_y = data[:offsety] || 0 @properties = data[:properties] || {} @fixed = @properties[:fixed] @image = @map.load_image(data[:image]) if data[:transparentcolor] color = data[:transparentcolor].sub("#", "").scan(/../).map{|c| c.to_i(16) } @image.set_color_key(color) end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 4 def data @data end |
#fixed ⇒ Object
Returns the value of attribute fixed.
5 6 7 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 5 def fixed @fixed end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 4 def name @name end |
#offset_x ⇒ Object
Returns the value of attribute offset_x.
5 6 7 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 5 def offset_x @offset_x end |
#offset_y ⇒ Object
Returns the value of attribute offset_y.
5 6 7 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 5 def offset_y @offset_y end |
#opacity ⇒ Object
Returns the value of attribute opacity.
5 6 7 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 5 def opacity @opacity end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
4 5 6 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 4 def properties @properties end |
#visible ⇒ Object
Returns the value of attribute visible.
5 6 7 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 5 def visible @visible end |
Instance Method Details
#draw(x, y, target = DXRuby::Window) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/dxruby_tiled/imagelayer.rb', line 26 def draw(x, y, target = DXRuby::Window) x = (x + target.width) % @map.pixel_width - target.width if @map.x_loop y = (y + target.height) % @map.pixel_height - target.height if @map.y_loop target.draw_alpha(@offset_x - (@fixed ? 0 : x), @offset_y - (@fixed? 0 : y), @image, (255 * @opacity).to_i) end |