Class: DXRuby::Tiled::ImageLayer

Inherits:
Layer
  • Object
show all
Defined in:
lib/dxruby_tiled/imagelayer.rb

Instance Attribute Summary collapse

Attributes inherited from Layer

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

Instance Method Summary collapse

Methods inherited from Layer

create

Constructor Details

#initialize(data, map) ⇒ ImageLayer

Returns a new instance of ImageLayer.



6
7
8
9
10
11
12
13
14
# File 'lib/dxruby_tiled/imagelayer.rb', line 6

def initialize(data, map)
  super
  @x_loop = !!@properties[:x_loop]
  @y_loop = !!@properties[:y_loop]
  @image  = map.load_image(data[:image], data[:transparentcolor])
  @map_loop = map.loop
  @map_pixel_width  = map.pixel_width
  @map_pixel_height = map.pixel_height
end

Instance Attribute Details

#fixedObject

Returns the value of attribute fixed.



4
5
6
# File 'lib/dxruby_tiled/imagelayer.rb', line 4

def fixed
  @fixed
end

#imageObject

Returns the value of attribute image.



4
5
6
# File 'lib/dxruby_tiled/imagelayer.rb', line 4

def image
  @image
end

#x_loopObject

Returns the value of attribute x_loop.



4
5
6
# File 'lib/dxruby_tiled/imagelayer.rb', line 4

def x_loop
  @x_loop
end

#y_loopObject

Returns the value of attribute y_loop.



4
5
6
# File 'lib/dxruby_tiled/imagelayer.rb', line 4

def y_loop
  @y_loop
end

Instance Method Details

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dxruby_tiled/imagelayer.rb', line 16

def render(x, y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0)
  x_range = 0..0
  if @x_loop
    x0 = (@offset_x + offset_x - (@fixed? 0 : x)) % @image.width
    x_range = -1..((target.width - 1) / @image.width)
  elsif @fixed
    x0 = @offset_x + offset_x
  elsif @map_loop
    x0 = (@offset_x + offset_x - x + target.width) % @map_pixel_width - target.width
  else
    x0 = @offset_x + offset_x - x
  end
  
  y_range = 0..0
  if @y_loop
    y0 = (@offset_y + offset_y - (@fixed? 0 : y)) % @image.height
    y_range = -1..((target.height - 1) / @image.height)
  elsif @fixed
    y0 = @offset_y + offset_y
  elsif @map_loop
    y0 = (@offset_y + offset_y - y + target.height) % @map_pixel_height - target.height
  else
    y0 = @offset_y + offset_y - y
  end
  
  x_range.each do |i_x|
    y_range.each do |i_y|
      target.draw_alpha(x0 + @image.width * i_x, y0 + @image.height * i_y,
                        @image, 255 * opacity * @opacity, z + @z_index)
    end
  end
end