Class: DXRuby::Tiled::OrthogonalLayer
- Inherits:
-
Layer
- Object
- Layer
- DXRuby::Tiled::OrthogonalLayer
show all
- Defined in:
- lib/dxruby_tiled/layer_orthogonal.rb
Instance Attribute Summary
Attributes inherited from Layer
#data, #height, #name, #offset_x, #offset_y, #opacity, #properties, #visible, #width
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Layer
#[], #[]=, #include?, #initialize
Class Method Details
.pixel_height(map) ⇒ Object
53
54
55
|
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 53
def self.pixel_height(map)
return map.tile_height * map.height
end
|
.pixel_width(map) ⇒ Object
49
50
51
|
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 49
def self.pixel_width(map)
return map.tile_width * map.width
end
|
Instance Method Details
#at(x, y) ⇒ Object
31
32
33
|
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 31
def at(x, y)
return self[x / @map.tile_width, y / @map.tile_height]
end
|
#change_at(x, y, value) ⇒ Object
35
36
37
|
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 35
def change_at(x, y, value)
self[x / @map.tile_width, y / @map.tile_height] = value
end
|
#draw(x, y, target = DXRuby::Window) ⇒ Object
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 5
def draw(x, y, target = DXRuby::Window)
tile_width, tile_height = @map.tile_width, @map.tile_height
tile_images = @map.tilesets.tile_images
left, top = xy_at(x - @offset_x, y - @offset_x)
x_range = left..(left + (target.width / tile_width + 1).floor)
y_range = top..(top + (target.height / tile_height + 1).floor)
off_x = left * tile_width + (x - @offset_x) % tile_width - tile_width / 2
off_y = top * tile_height + (y - @offset_y) % tile_height - tile_height / 2
alpha = (@opacity * 255).floor
x_range = x_range.to_a.reverse if @map.renderorder_x
y_range = y_range.to_a.reverse if @map.renderorder_y
y_range.each do |yy|
x_range.each do |xx|
image = tile_images[self[xx, yy]]
target.draw_alpha(xx * tile_width - off_x - image.width / 2,
yy * tile_height - off_y - image.height / 2,
image, alpha)
end
end
end
|
#vertexs(x, y) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 39
def vertexs(x, y)
w, h = @map.tile_width, @map.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(x, y) ⇒ Object
27
28
29
|
# File 'lib/dxruby_tiled/layer_orthogonal.rb', line 27
def xy_at(x, y)
return x / @map.tile_width, y / @map.tile_height
end
|