Class: ParticleFX2D::Ruby2D::CanvasRendererFactory
- Inherits:
-
Object
- Object
- ParticleFX2D::Ruby2D::CanvasRendererFactory
- Defined in:
- lib/particlefx2d/ruby2d/canvas_renderer_factory.rb
Overview
A shared surface renderer that uses Ruby2D’s Canvas to draw into. This is both a factory and the renderer/
This approach uses the same renderer for all particles in an emitter.
Instance Method Summary collapse
-
#draw_particle(particle) ⇒ Object
Updates the shape’s properties; no explicit drawing needed.
-
#hide_particle(_particle) ⇒ Object
Hide the particle.
-
#initialize(canvas) ⇒ CanvasRendererFactory
constructor
Instantiate a shape renderer factory.
-
#on_update_end ⇒ Object
Update the canvas at the end of the next update cycle.
-
#on_update_start ⇒ Object
Clear the canvas before the next update cycle.
-
#renderer_for(_particle) ⇒ Renderer
Return a particle renderer.
-
#show_particle(_particle) ⇒ Object
Show the particle.
Methods included from ParticleFX2D::Renderer
Constructor Details
#initialize(canvas) ⇒ CanvasRendererFactory
Instantiate a shape renderer factory.
19 20 21 22 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 19 def initialize(canvas) @canvas = canvas @fill_method = canvas.class.method_defined?(:fill_rectangle, true) end |
Instance Method Details
#draw_particle(particle) ⇒ Object
Updates the shape’s properties; no explicit drawing needed.
50 51 52 53 54 55 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 50 def draw_particle(particle) size = particle.size x = particle.x - (size / 2) y = particle.y - (size / 2) fill_rect(x, y, size, size, particle.color.to_a) end |
#hide_particle(_particle) ⇒ Object
Hide the particle. Used when a particle is deactivated.
47 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 47 def hide_particle(_particle); end |
#on_update_end ⇒ Object
Update the canvas at the end of the next update cycle
37 38 39 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 37 def on_update_end @canvas.update end |
#on_update_start ⇒ Object
Clear the canvas before the next update cycle
32 33 34 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 32 def on_update_start fill_rect(0, 0, @canvas.width, @canvas.height, [0, 0, 0, 0]) end |
#renderer_for(_particle) ⇒ Renderer
Return a particle renderer.
27 28 29 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 27 def renderer_for(_particle) self end |
#show_particle(_particle) ⇒ Object
Show the particle. Used when a particle is activated.
44 |
# File 'lib/particlefx2d/ruby2d/canvas_renderer_factory.rb', line 44 def show_particle(_particle); end |