Class: DXRuby::Tiled::OrthogonalLayer

Inherits:
TileLayer show all
Defined in:
lib/dxruby_tiled/layer_orthogonal.rb

Instance Attribute Summary

Attributes inherited from TileLayer

#height, #startx, #starty, #width

Attributes inherited from Layer

#name, #offset_x, #offset_y, #opacity, #properties, #visible, #z_index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TileLayer

#[], #[]=, #include?, #initialize, #tile_at

Methods inherited from Layer

create, #initialize

Constructor Details

This class inherits a constructor from DXRuby::Tiled::TileLayer

Class Method Details

.pixel_height(map) ⇒ Object



54
55
56
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 54

def self.pixel_height(map)
  map.tile_height * map.height
end

.pixel_width(map) ⇒ Object



50
51
52
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 50

def self.pixel_width(map)
  map.tile_width * map.width
end

Instance Method Details

#at(pos_x, pos_y) ⇒ Object



32
33
34
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 32

def at(pos_x, pos_y)
  self[pos_x.to_i / @tile_width, pos_y.to_i / @tile_height]
end

#change_at(pos_x, pos_y, value) ⇒ Object



36
37
38
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 36

def change_at(pos_x, pos_y, value)
  self[pos_x.to_i / @tile_width, pos_y.to_i / @tile_height] = value
end

#render(pos_x, pos_y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0) ⇒ Object Also known as: draw



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 4

def render(pos_x, pos_y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0)
  super
  
  pos_x, pos_y = 0, 0 if @fixed
  off_x = offset_x + @offset_x - pos_x
  off_y = offset_y + @offset_y - pos_y
  x1, y1 = xy_at(@tile_width  - @tilesets.tile_right  - off_x,
                 @tile_height - @tilesets.tile_bottom - off_y)
  x2, y2 = xy_at(@render_target.width  - @tilesets.tile_left - off_x - 1,
                 @render_target.height - @tilesets.tile_top  - off_y - 1)
  
  (y1..(y2 + 1)).public_send(@renderorder_y ? :each : :reverse_each) do |y|
    (x1..(x2 + 1)).public_send(@renderorder_x ? :each : :reverse_each) do |x|
      @tilesets[self[x, y]].render(
        x * @tile_width  + off_x,
        y * @tile_height + off_y,
        @render_target)
    end
  end
  
  target.draw_alpha(0, 0, @render_target, @opacity * 255, z + @z_index)
end

#vertexs(x, y) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 40

def vertexs(x, y)
  w, h = @tile_width, @tile_height
  return [
    [ x * w    , y * h     ],
    [ x * w    , y * h + h ],
    [ x * w + w, y * h + h ],
    [ x * w + w, y * h     ]
  ]
end

#xy_at(pos_x, pos_y) ⇒ Object



28
29
30
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 28

def xy_at(pos_x, pos_y)
  return pos_x.to_i / @tile_width, pos_y.to_i / @tile_height
end