Class: DXRuby::Tiled::ImageLayer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, map) ⇒ ImageLayer

Returns a new instance of ImageLayer.



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

def initialize(data, map)
  @original_data = data
  @map = map
  
  @name       = data[:name]
  @opacity    = data[:opacity]    || 1.0
  @visible    = data[:visible] != false
  @offset_x   = data[:offsetx]    || 0
  @offset_y   = data[:offsety]    || 0
  @properties = data[:properties] || {}
  @fixed      = @properties[:fixed]
  
  @image      = @map.load_image(data[:image])
  if data[:transparentcolor]
    color = data[:transparentcolor].sub("#", "").scan(/../).map{|c| c.to_i(16) }
    @image.set_color_key(color)
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#fixedObject

Returns the value of attribute fixed.



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

def fixed
  @fixed
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#offset_xObject

Returns the value of attribute offset_x.



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

def offset_x
  @offset_x
end

#offset_yObject

Returns the value of attribute offset_y.



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

def offset_y
  @offset_y
end

#opacityObject

Returns the value of attribute opacity.



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

def opacity
  @opacity
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#visibleObject

Returns the value of attribute visible.



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

def visible
  @visible
end

Instance Method Details

#draw(x, y, target = DXRuby::Window) ⇒ Object



26
27
28
29
30
31
# File 'lib/dxruby_tiled/imagelayer.rb', line 26

def draw(x, y, target = DXRuby::Window)
  x = (x + target.width)  % @map.pixel_width  - target.width  if @map.x_loop
  y = (y + target.height) % @map.pixel_height - target.height if @map.y_loop
  target.draw_alpha(@offset_x - (@fixed ? 0 : x), @offset_y - (@fixed? 0 : y),
                    @image, (255 * @opacity).to_i)
end