Class: ParticleFX2D::Emitter
- Inherits:
-
Object
- Object
- ParticleFX2D::Emitter
- Defined in:
- lib/particlefx2d/emitter.rb
Overview
A particle effect emitter
Instance Attribute Summary collapse
-
#emission_rate ⇒ Object
Returns the value of attribute emission_rate.
-
#particle_config ⇒ Object
Returns the value of attribute particle_config.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Emitter
constructor
Create a new particle emitter.
-
#stats ⇒ Object
Retrieve statistics about the emitter's current status.
-
#update(frame_time) ⇒ Object
Update the particle effect emission, called for each frame of the animation cycle.
Constructor Details
#initialize(opts = {}) ⇒ Emitter
Create a new particle emitter
quantityNumber of total particles in the emitter's poolemission_rateNumber of particles to emit per second-
particle_configOptions are used to configure each particle when it is emitted, which are as follows:xInitial x-axis position of emissionx_rangeoptional range from which a random value is chosen to add to the initialx; default is 0yInitial y-axis position of emissiony_rangeoptional range from which a random value is chosen to add to the initialy; default is 0start_coloroptional initial colour of the emitted particle. SeeParticlefor defaultend_coloroptional end colour of the particle by the end of its life. SeeParticlefor defaultstart_scaleoptional initial size scale factor of the emitted particle relative to itssize; default is 1end_scaleoptional end size scale factor of the particle by the end of its life; default is 1angleoptional angle at which the particle is emitted, in degrees. SeeParticlefor defaultangle_rangeoptional range from which a random value is chosen to add to theangle; default is 0speedoptional speed at which the particle is emitted, in pixels/s. SeeParticlefor defaultspeed_rangeoptional range from which a random value is chosen to add to thespeed; default is 0sizeoptional size of the particle when emitted, in pixels. SeeParticlefor defaultsize_rangeoptional range from which a random value is chosen to add to thesize; default is 0gravity_xoptional linear acceleration in pixels/second squared along the x axis, default is 0gravity_yoptional linear acceleration in pixels/second squared along the y axis, default is 0radial_accelerationoptional radial accelation in pixel/seconds squared, default is 0tangential_accelerationoptional tangential accelation in pixel/seconds squared, default is 0life_timeof each particle in seconds. SeeParticlefor defaultlife_time_rangeoptional range from which a random value is chosen to add to thelife_time; default is 0
38 39 40 41 42 43 44 45 |
# File 'lib/particlefx2d/emitter.rb', line 38 def initialize(opts = {}) @quantity = (opts[:quantity] || 128).to_i @emission_rate = opts[:emission_rate].to_f @emission = 0 @particle_config = opts[:particle_config] @renderer_factory = opts[:renderer_factory] setup_particle_pool end |
Instance Attribute Details
#emission_rate ⇒ Object
Returns the value of attribute emission_rate.
8 9 10 |
# File 'lib/particlefx2d/emitter.rb', line 8 def emission_rate @emission_rate end |
#particle_config ⇒ Object
Returns the value of attribute particle_config.
8 9 10 |
# File 'lib/particlefx2d/emitter.rb', line 8 def particle_config @particle_config end |
Instance Method Details
#stats ⇒ Object
Retrieve statistics about the emitter's current status
quantityThe total number of particles in the emitteremission_rateThe emission rate (particles per second)activeThe number of active particlesunusedThe number of inactive particles in the pool
71 72 73 74 75 76 77 78 |
# File 'lib/particlefx2d/emitter.rb', line 71 def stats { quantity: @quantity, emission_rate: @emission_rate, active: @active.count, unused: @pool.count } end |
#update(frame_time) ⇒ Object
Update the particle effect emission, called for each frame of the animation cycle.
52 53 54 55 56 57 58 59 60 |
# File 'lib/particlefx2d/emitter.rb', line 52 def update(frame_time) @renderer_factory.on_update_start emit_particles frame_time @active.each do |p| p.update frame_time free_particle p unless p.alive? end @renderer_factory.on_update_end end |