Class: DXRuby::Tiled::IsometricLayer

Inherits:
TileLayer show all
Defined in:
lib/dxruby_tiled/layer_isometric.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

#[], #[]=, #at, #change_at, #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



51
52
53
# File 'lib/dxruby_tiled/layer_isometric.rb', line 51

def self.pixel_height(map)
  map.tile_height * (map.width + map.height) / 2
end

.pixel_width(map) ⇒ Object



47
48
49
# File 'lib/dxruby_tiled/layer_isometric.rb', line 47

def self.pixel_width(map)
  map.tile_width  * (map.width + map.height) / 2
end

Instance Method Details

#render(pos_x, pos_y, target = DXRuby::Window, z = @z_index, 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
26
27
28
# File 'lib/dxruby_tiled/layer_isometric.rb', line 4

def render(pos_x, pos_y, target = DXRuby::Window, z = @z_index, offset_x = 0, offset_y = 0, opacity = 1.0)
  super
  
  pos_x, pos_y = 0, 0 if @fixed
  tile_width2, tile_height2 = @tile_width / 2, @tile_height / 2
  off_x = offset_x + @offset_x - pos_x
  off_y = offset_y + @offset_y - pos_y
  left, top = xy_at(@tile_width  - @tilesets.tile_right  - off_x,
                    @tile_height - @tilesets.tile_bottom - off_y)
  x_range = -1..((@render_target.width  - @tilesets.tile_left)    / @tile_width  + 2)
  y_range = -1..((@render_target.height - @tilesets.tile_top) * 2 / @tile_height + 4)
  
  y_range.public_send(@renderorder_y ? :each : :reverse_each) do |tmp_y|
    x_range.public_send(@renderorder_x ? :each : :reverse_each) do |tmp_x|
      x = left + tmp_x + tmp_y / 2
      y = top + (tmp_y + 1) / 2 - tmp_x
      @tilesets[self[x, y]].render(
        x * tile_width2  - y * tile_width2  + off_x,
        y * tile_height2 + x * tile_height2 + off_y,
        @render_target)
    end
  end
  
  target.draw_alpha(0, 0, @render_target, @opacity * 255, z + @z_index)
end

#vertexs(x, y) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/dxruby_tiled/layer_isometric.rb', line 36

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

#xy_at(pos_x, pos_y) ⇒ Object



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

def xy_at(pos_x, pos_y)
  return (1.0 * pos_x / @tile_width  + 1.0 * pos_y / @tile_height).floor,
         (1.0 * pos_y / @tile_height - 1.0 * pos_x / @tile_width ).floor
end