Class: Kawaii::TmxLayer
- Inherits:
-
Object
- Object
- Kawaii::TmxLayer
- Defined in:
- lib/kawaii/tmx_layer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#height ⇒ Object
Returns the value of attribute height.
-
#name ⇒ Object
Returns the value of attribute name.
-
#opacity ⇒ Object
Returns the value of attribute opacity.
-
#textures ⇒ Object
Returns the value of attribute textures.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #draw ⇒ Object
- #get_cell(col, row) ⇒ Object
-
#initialize(hash) ⇒ TmxLayer
constructor
A new instance of TmxLayer.
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ TmxLayer
Returns a new instance of TmxLayer.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/kawaii/tmx_layer.rb', line 6 def initialize hash @data = [] hash['data'].each{|cell| @data.push cell} @name = hash['name'] @opacity = hash['opacity'] @width = hash['width'] @height = hash['height'] @x = hash['x'] @y = hash['y'] @textures = nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def data @data end |
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def height @height end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def name @name end |
#opacity ⇒ Object
Returns the value of attribute opacity.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def opacity @opacity end |
#textures ⇒ Object
Returns the value of attribute textures.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def textures @textures end |
#width ⇒ Object
Returns the value of attribute width.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
4 5 6 |
# File 'lib/kawaii/tmx_layer.rb', line 4 def y @y end |
Instance Method Details
#draw ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kawaii/tmx_layer.rb', line 33 def draw @width.times do |i| @height.times do |j| cell = get_cell(i, j) if(cell != 0) @textures[cell-1].draw(i * 32, j * 32, 0) end end end end |
#get_cell(col, row) ⇒ Object
18 19 20 21 22 |
# File 'lib/kawaii/tmx_layer.rb', line 18 def get_cell col, row #puts "Getting cell w col:#{col} and row: #{row} and it has the value #{@data[col + row * @width]}" #puts @data @data[col + row * @width] end |
#to_s ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/kawaii/tmx_layer.rb', line 24 def to_s puts "Name: #{name}" puts "Opacity: #{opacity}" puts "Width: #{width}" puts "Height: #{height}" puts "X: #{x}" puts "Y: #{y}" end |