Class: DXRuby::Tiled::TileLayer
- Inherits:
-
Layer
- Object
- Layer
- DXRuby::Tiled::TileLayer
show all
- Defined in:
- lib/dxruby_tiled/tilelayer.rb
Instance Attribute Summary collapse
Attributes inherited from Layer
#name, #offset_x, #offset_y, #opacity, #properties, #visible, #z_index
Instance Method Summary
collapse
-
#[](x, y) ⇒ Object
-
#[]=(x, y, value) ⇒ Object
-
#at(pos_x, pos_y) ⇒ Object
-
#change_at(pos_x, pos_y, value) ⇒ Object
-
#include?(x, y) ⇒ Boolean
(also: #member?)
-
#initialize(data, map) ⇒ TileLayer
constructor
A new instance of TileLayer.
-
#render(pos_x, pos_y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0) ⇒ Object
(also: #draw)
-
#tile_at(pos_x, pos_y) ⇒ Object
Methods inherited from Layer
create
Constructor Details
#initialize(data, map) ⇒ TileLayer
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 6
def initialize(data, map)
super
if data[:chunks]
@x1 = data[:chunks].map {|chunk| chunk[:x] }.min
@y1 = data[:chunks].map {|chunk| chunk[:y] }.min
@x2 = data[:chunks].map {|chunk| chunk[:x] + chunk[:width ] }.max
@y2 = data[:chunks].map {|chunk| chunk[:y] + chunk[:height] }.max
@data = Array.new((@x2 - @x1) * (@y2 - @y1), 0)
data[:chunks].each do |chunk|
get_data(chunk[:data], data[:encoding], data[:compression]).each_with_index do |d, i|
x, y = chunk[:x] + i % chunk[:width] - @x1, chunk[:y] + i / chunk[:width] - @y1
@data[y * (@x2 - @x1) + x] = d
end
end
else
@x1 = data[:startx] || 0
@y1 = data[:starty] || 0
@x2 = @x1 + (data[:width ] || map.width )
@y2 = @y1 + (data[:height] || map.height)
@data = get_data(data[:data], data[:encoding], data[:compression])
end
@startx = @x1
@starty = @y1
@width = @x2 - @x1
@height = @y2 - @y1
@tile_width = map.tile_width
@tile_height = map.tile_height
@renderorder_x = map.renderorder_x
@renderorder_y = map.renderorder_y
@render_target = DXRuby::RenderTarget.new(DXRuby::Window.width, DXRuby::Window.height)
@tilesets = map.tilesets
self.extend LoopTileLayer if map.loop
end
|
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
4
5
6
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 4
def height
@height
end
|
#startx ⇒ Object
Returns the value of attribute startx.
4
5
6
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 4
def startx
@startx
end
|
#starty ⇒ Object
Returns the value of attribute starty.
4
5
6
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 4
def starty
@starty
end
|
#width ⇒ Object
Returns the value of attribute width.
4
5
6
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 4
def width
@width
end
|
Instance Method Details
#[](x, y) ⇒ Object
41
42
43
44
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 41
def [](x, y)
x < @x1 || x >= @x2 || y < @y1 || y >= @y2 ?
0 : @data[(y - @y1) * @width + x - @x1]
end
|
#[]=(x, y, value) ⇒ Object
46
47
48
49
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 46
def []=(x, y, value)
return if x < @x1 || x >= @x2 || y < @y1 || y >= @y2
@data[(y - @y1) * @width + x - @x1] = value
end
|
#at(pos_x, pos_y) ⇒ Object
56
57
58
59
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 56
def at(pos_x, pos_y)
x, y = xy_at(pos_x, pos_y)
self[x, y]
end
|
#change_at(pos_x, pos_y, value) ⇒ Object
61
62
63
64
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 61
def change_at(pos_x, pos_y, value)
x, y = xy_at(pos_x, pos_y)
self[x, y] = value
end
|
#include?(x, y) ⇒ Boolean
Also known as:
member?
51
52
53
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 51
def include?(x, y)
x >= @x1 && x < @x2 && y >= @y1 && y < @y2
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
70
71
72
73
74
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 70
def render(pos_x, pos_y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0)
unless @render_target.width == target.width && @render_target.height == target.height
@render_target.resize(target.width, target.height)
end
end
|
#tile_at(pos_x, pos_y) ⇒ Object
66
67
68
|
# File 'lib/dxruby_tiled/tilelayer.rb', line 66
def tile_at(pos_x, pos_y)
@tilesets[at(pos_x, pos_y)]
end
|