EmitterProperties

class pygamelib.gfx.particles.EmitterProperties(row: int = 0, column: int = 0, variance: float = 2.0, emit_number: int = 1, emit_rate: float = 0.1, lifespan: int = 200, parent=None, particle_velocity=None, particle_acceleration=None, particle_lifespan: float = 5.0, radius: float = 1.0, particle: Particle = None)

Bases: object

EmitterProperties is a class that hold configuration variables for a particle emitter. The idea is that it’s easier to carry around for multiple emitters with the same configuration than multiple values in the emitter’s constructor.

It holds all possible parmeters for all types of emitters. Emitters uses only the ones that they really need.

Important

In most cases these values are copied by the emitter’s constructor. So changing the values during an emitter’s alive cycle is not going to do anything.

Note

This class should be a @dataclass. However, support for keyword only data classes is specific to python 3.10+. So for now, it is a regular class.

__init__(row: int = 0, column: int = 0, variance: float = 2.0, emit_number: int = 1, emit_rate: float = 0.1, lifespan: int = 200, parent=None, particle_velocity=None, particle_acceleration=None, particle_lifespan: float = 5.0, radius: float = 1.0, particle: Particle = None) None
Parameters:
  • row (int) – The row where the emitter is. It is only important for the first rendering cycle. After that, the emitter will know its position on screen.

  • column (int) – The row where the emitter is. It is only important for the first rendering cycle. After that, the emitter will know its position on screen.

  • variance (float) – The variance is the amount of randomness that is allowed when emitting a particle. The exact use of this parameter is specific to each emitter.

  • emit_number (int) – The number of particle emitted at each timer tick.

  • emit_rate (float) – The rate of emission in seconds. This value needs to be understood as “the emitter will emit emit_number particles every emit_rate seconds”.

  • lifespan (int) – The lifespan of the emitter in number of emission cycle. If lifespan is set to 1 for example, the emitter will only emit one burst of particles.

  • parent (BoardItem) – A parent board item. If you do that manually, you will probably want to set it specifically for each emitter.

  • particle_velocity (Vector2D) – The initial particle velocity. Please read the documentation of each emitter for the specific use of particle velocity.

  • particle_acceleration (Vector2D) – The initial particle acceleration. Please read the documentation of each emitter for the specific use of particle acceleration.

  • particle_lifespan (int) – The lifespan of the particle in number of cycles.

  • radius (float) – For emitter that supports it (like the CircleEmitter), sets the radius of emission (which translate into a velocity vector for each particle).

  • particle (Particle) – The particle that the emitter will emit. This can be a class reference or a fully instantiated particle. Emitters will copy it in the particle pool.

Example:

props = EmitterProperties(emit_number=10, emit_rate=0.1, lifespan=10)

Methods

__init__([row, column, variance, ...])

param row:

The row where the emitter is. It is only important for the first

load(data)

Load an EmitterProperties from a dictionary.

serialize()

Serialize an EmitterProperties into a dictionary.

classmethod load(data)

Load an EmitterProperties from a dictionary.

Parameters:

data (dict) – The dictionary to load from.

Returns:

The EmitterProperties object

Return type:

EmitterProperties

Example:

emitter_properties = EmitterProperties.load(
                        json.load( open("emitter_properties.json") )
                    )
serialize()

Serialize an EmitterProperties into a dictionary.

Returns:

The class as a dictionary

Return type:

dict

Example:

json.dump( emitter_properties.serialize() )