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 pool -
emission_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 emission -
x_rangeoptional range from which a random value is chosen to add to the initialx; default is 0 -
yInitial y-axis position of emission -
y_rangeoptional range from which a random value is chosen to add to the initialy; default is 0 -
start_coloroptional initial colour of the emitted particle. See ‘Particle` for default -
end_coloroptional end colour of the particle by the end of its life. See ‘Particle` for default -
start_scaleoptional initial size scale factor of the emitted particle relative to itssize; default is 1 -
end_scaleoptional end size scale factor of the particle by the end of its life; default is 1 -
angleoptional angle at which the particle is emitted, in degrees. See ‘Particle` for default -
angle_rangeoptional range from which a random value is chosen to add to theangle; default is 0 -
speedoptional speed at which the particle is emitted, in pixels/s. See ‘Particle` for default -
speed_rangeoptional range from which a random value is chosen to add to thespeed; default is 0 -
sizeoptional size of the particle when emitted, in pixels. See ‘Particle` for default -
size_rangeoptional range from which a random value is chosen to add to thesize; default is 0 -
gravity_xoptional linear acceleration in pixels/second squared along the x axis, default is 0 -
gravity_yoptional linear acceleration in pixels/second squared along the y axis, default is 0 -
radial_accelerationoptional radial accelation in pixel/seconds squared, default is 0 -
tangential_accelerationoptional tangential accelation in pixel/seconds squared, default is 0 -
life_timeof each particle in seconds. See ‘Particle` for default -
life_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 emitter -
emission_rateThe emission rate (particles per second) -
activeThe number of active particles -
unusedThe 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 |