Class: DXRuby::Tiled::Tile
- Inherits:
-
Object
- Object
- DXRuby::Tiled::Tile
- Defined in:
- lib/dxruby_tiled/tile.rb
Instance Attribute Summary collapse
-
#adjusted_offset_y ⇒ Object
readonly
Returns the value of attribute adjusted_offset_y.
-
#angle ⇒ Object
readonly
Returns the value of attribute angle.
-
#collision ⇒ Object
Returns the value of attribute collision.
-
#collision_enable ⇒ Object
Returns the value of attribute collision_enable.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#offset_x ⇒ Object
readonly
Returns the value of attribute offset_x.
-
#offset_y ⇒ Object
readonly
Returns the value of attribute offset_y.
-
#original_image ⇒ Object
readonly
Returns the value of attribute original_image.
-
#scale_x ⇒ Object
readonly
Returns the value of attribute scale_x.
-
#scale_y ⇒ Object
readonly
Returns the value of attribute scale_y.
-
#tileset ⇒ Object
readonly
Returns the value of attribute tileset.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #animate(current_time) ⇒ Object
- #animate!(current_time) ⇒ Object
- #height ⇒ Object
-
#initialize(image, offset_x, offset_y, adjusted_offset_y, tileset = nil) ⇒ Tile
constructor
A new instance of Tile.
- #render(x, y, target = DXRuby::Window, z_index = 0) ⇒ Object (also: #draw)
- #set_animation(anim_time, anim_tile) ⇒ Object
- #to_sprite(x, y) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(image, offset_x, offset_y, adjusted_offset_y, tileset = nil) ⇒ Tile
Returns a new instance of Tile.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dxruby_tiled/tile.rb', line 8 def initialize(image, offset_x, offset_y, adjusted_offset_y, tileset = nil) @image = @original_image = image @offset_x = offset_x @offset_y = offset_y @adjusted_offset_y = adjusted_offset_y @tileset = tileset @type = nil @anim_time_total = 1 @anim_time = [0] @anim_tile = [self] @collision = nil @collision_enable = true @scale_x = 1 @scale_y = 1 @angle = 0 end |
Instance Attribute Details
#adjusted_offset_y ⇒ Object (readonly)
Returns the value of attribute adjusted_offset_y.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def adjusted_offset_y @adjusted_offset_y end |
#angle ⇒ Object (readonly)
Returns the value of attribute angle.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def angle @angle end |
#collision ⇒ Object
Returns the value of attribute collision.
6 7 8 |
# File 'lib/dxruby_tiled/tile.rb', line 6 def collision @collision end |
#collision_enable ⇒ Object
Returns the value of attribute collision_enable.
6 7 8 |
# File 'lib/dxruby_tiled/tile.rb', line 6 def collision_enable @collision_enable end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def image @image end |
#offset_x ⇒ Object (readonly)
Returns the value of attribute offset_x.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def offset_x @offset_x end |
#offset_y ⇒ Object (readonly)
Returns the value of attribute offset_y.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def offset_y @offset_y end |
#original_image ⇒ Object (readonly)
Returns the value of attribute original_image.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def original_image @original_image end |
#scale_x ⇒ Object (readonly)
Returns the value of attribute scale_x.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def scale_x @scale_x end |
#scale_y ⇒ Object (readonly)
Returns the value of attribute scale_y.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def scale_y @scale_y end |
#tileset ⇒ Object (readonly)
Returns the value of attribute tileset.
4 5 6 |
# File 'lib/dxruby_tiled/tile.rb', line 4 def tileset @tileset end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/dxruby_tiled/tile.rb', line 6 def type @type end |
Instance Method Details
#animate(current_time) ⇒ Object
33 34 35 36 |
# File 'lib/dxruby_tiled/tile.rb', line 33 def animate(current_time) time = current_time % @anim_time_total @anim_tile[@anim_time.rindex { |t| time >= t } ] end |
#animate!(current_time) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/dxruby_tiled/tile.rb', line 38 def animate!(current_time) time = current_time % @anim_time_total tile = @anim_tile[@anim_time.rindex { |t| time >= t } ] @image = tile.original_image @offset_x = tile.offset_x @offset_y = tile.offset_y @adjusted_offset_y = tile.adjusted_offset_y end |
#height ⇒ Object
26 |
# File 'lib/dxruby_tiled/tile.rb', line 26 def height; @image.height; end |
#render(x, y, target = DXRuby::Window, z_index = 0) ⇒ Object Also known as: draw
28 29 30 |
# File 'lib/dxruby_tiled/tile.rb', line 28 def render(x, y, target = DXRuby::Window, z_index = 0) target.draw(x + @offset_x, y + @adjusted_offset_y, @image, z_index) end |
#set_animation(anim_time, anim_tile) ⇒ Object
47 48 49 50 51 |
# File 'lib/dxruby_tiled/tile.rb', line 47 def set_animation(anim_time, anim_tile) @anim_time = anim_time @anim_tile = anim_tile @anim_time_total = @anim_time.pop end |
#to_sprite(x, y) ⇒ Object
53 54 55 |
# File 'lib/dxruby_tiled/tile.rb', line 53 def to_sprite(x, y) TileObject.new(x: x, y: y, tile: self) end |
#width ⇒ Object
25 |
# File 'lib/dxruby_tiled/tile.rb', line 25 def width ; @image.width ; end |