Class: Renderer
Instance Method Summary collapse
- #clear_drawables ⇒ Object
- #draw(target) ⇒ Object
-
#initialize ⇒ Renderer
constructor
A new instance of Renderer.
-
#move_layer(from_parallax, from_layer, to_parallax, to_layer) ⇒ Object
move all actors from one layer to another note, this will remove all actors in that layer!.
- #register_drawable(drawable) ⇒ Object
- #unregister_drawable(drawable) ⇒ Object
Constructor Details
#initialize ⇒ Renderer
Returns a new instance of Renderer.
4 5 6 |
# File 'lib/gamebox/core/renderer.rb', line 4 def initialize clear_drawables end |
Instance Method Details
#clear_drawables ⇒ Object
27 28 29 30 31 |
# File 'lib/gamebox/core/renderer.rb', line 27 def clear_drawables @drawables = {} @layer_orders = {} @parallax_layers = [] end |
#draw(target) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gamebox/core/renderer.rb', line 34 def draw(target) center_x = .width / 2 center_y = .height / 2 target.rotate(-.rotation, center_x, center_y) do z = 0 @parallax_layers.each do |parallax_layer| drawables_on_parallax_layer = @drawables[parallax_layer] if drawables_on_parallax_layer @layer_orders[parallax_layer].each do |layer| trans_x = .x_offset parallax_layer trans_y = .y_offset parallax_layer z += 1 drawables_on_parallax_layer[layer].each do |drawable| drawable.draw target, trans_x, trans_y, z end end end end end end |
#move_layer(from_parallax, from_layer, to_parallax, to_layer) ⇒ Object
move all actors from one layer to another note, this will remove all actors in that layer!
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gamebox/core/renderer.rb', line 61 def move_layer(from_parallax, from_layer, to_parallax, to_layer) drawable_list = @drawables[from_parallax][from_layer].dup drawable_list.each do |drawable| unregister_drawable drawable drawable.parallax = to_parallax drawable.layer = to_layer register_drawable drawable end end |
#register_drawable(drawable) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gamebox/core/renderer.rb', line 8 def register_drawable(drawable) layer = drawable.layer parallax = drawable.parallax unless @drawables[parallax] @drawables[parallax] = {} @parallax_layers = @drawables.keys.sort.reverse end unless @drawables[parallax][layer] @drawables[parallax][layer] = [] @layer_orders[parallax] = @drawables[parallax].keys.sort end @drawables[parallax][layer] << drawable end |
#unregister_drawable(drawable) ⇒ Object
23 24 25 |
# File 'lib/gamebox/core/renderer.rb', line 23 def unregister_drawable(drawable) @drawables[drawable.parallax][drawable.layer].delete drawable end |