Class: DXRuby::Tiled::ObjectGroup
- Defined in:
- lib/dxruby_tiled/objectgroup.rb
Instance Attribute Summary collapse
-
#draworder ⇒ Object
readonly
Returns the value of attribute draworder.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Attributes inherited from Layer
#name, #offset_x, #offset_y, #opacity, #properties, #visible, #z_index
Instance Method Summary collapse
-
#initialize(data, map) ⇒ ObjectGroup
constructor
A new instance of ObjectGroup.
- #render(x, y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0) ⇒ Object (also: #draw)
Methods inherited from Layer
Constructor Details
#initialize(data, map) ⇒ ObjectGroup
Returns a new instance of ObjectGroup.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 6 def initialize(data, map) super @x = data[:x] || 0 @y = data[:y] || 0 @width = data[:width ] || map.width @height = data[:height] || map.height @draworder = data[:draworder] || "topdown" @render_target = DXRuby::RenderTarget.new(DXRuby::Window.width, DXRuby::Window.height) @objects = data[:objects].map do |object_hash| object = TMEObject.create_from_hash(object_hash, map) object.target = @render_target if object.is_a? TileObject object.scale_x = 1.0 * object_hash[:width ] / object.image.width * object.scale_x object.scale_y = 1.0 * object_hash[:height] / object.image.height * object.scale_y end object end end |
Instance Attribute Details
#draworder ⇒ Object (readonly)
Returns the value of attribute draworder.
4 5 6 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 4 def draworder @draworder end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 4 def height @height end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
4 5 6 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 4 def objects @objects end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 4 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 4 def y @y 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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dxruby_tiled/objectgroup.rb', line 26 def render(x, y, target = DXRuby::Window, z = 0, offset_x = 0, offset_y = 0, opacity = 1.0) if @render_target.width != target.width || @render_target.height != target.height @render_target.resize(target.width, target.height) end @render_target.ox = offset_x + @offset_x + (@fixed ? 0 : x) @render_target.oy = offset_y + @offset_y + (@fixed ? 0 : y) DXRuby::Sprite.update(@objects) DXRuby::Sprite.clean(@objects) DXRuby::Sprite.draw( case @draworder when "topdown" then @objects.sort_by { |obj| obj.y } when "index" then @objects.sort_by { |obj| obj.object_id } else @objects end ) target.draw_alpha(0, 0, @render_target, @opacity * 255, z + @z_index) end |