Skip to content

particle

FreeBodyEngine.core.particle #

PARTICLE_DTYPE = np.dtype([('pos', np.float32, (2,)), ('vel', np.float32, (2,)), ('lifetime', np.float32), ('active', np.bool_)]) module-attribute #

ParticleEmmiter(position=Vector(), rotation=1, scale=Vector(), particle_settings=ParticleSettings()) #

Bases: Node2D

Spawns and simulates a pool of particles on a fixed-size, struct-of-arrays NumPy buffer (self.particles, dtype PARTICLE_DTYPE) rather than one object per particle, so large particle counts stay cheap.

Allocates the fixed-size particle buffer (sized to particle_settings.max_particles) and starts the spawn cooldown timer.

free_list tracks which slots in self.particles are unused - a spawn pops a slot from it, and a particle's death pushes its slot back on, so the buffer never needs to grow or shrink.

active = np.zeros(self.particle_settings.max_particles, dtype=bool) instance-attribute #

free_list = list(range(self.particle_settings.max_particles)) instance-attribute #

particle_settings = particle_settings instance-attribute #

particles = np.zeros(particle_settings.max_particles, dtype=PARTICLE_DTYPE) instance-attribute #

spawn_timer = Timer(self.particle_settings.spawn_cooldown) instance-attribute #

activate() #

Resumes spawning and simulating particles.

deactivate() #

Stops spawning and simulating particles (on_update() becomes a no-op) - existing particles are left as they are, not cleared.

on_update() #

While active, spawns a new particle whenever the spawn cooldown completes, ages and moves all currently-alive particles, and recycles any whose lifetime has run out back onto free_list.

ParticleSettings(velocity_min=Vector(), velocity_max=Vector(1, 1), lifetime=-1.0, spawn_cooldown=0.1, max_particles=100, acceleration_min=Vector(), acceleration_max=Vector(1, 1), color=None, texture=None, texture_stack=None) dataclass #

The information that controlls the attributes of particle. Attributes with minimum and maximum values will be given a value between the max and min.

:param velocity_min: The minimum initial velocity. :type velocity_min: Vector :param velocity_max: The maximum initial velocity. :type velocity_max: Vector :param lifetime: The time a particle will last for. A value of -1 will make it last forever. :type lifetime: float :param spawn_cooldown: The cooldown between particle spawns. :type spawn_cooldown: float :param max_particles: The maximum amount of particles that can exist at any time. :type max_particles: int :param acceleration_min: The minimum acceleration. :type acceleration_min: Vector :param acceleration_max: The maximum acceleration. :type acceleration_max: Vector :param color: If color is set, the particle will use a flat color. :type color: Color :param texture: If texture is set, the particle will use the texture. :type texture: Texture :param texture_stack: If texture_stack is set, a random image in the stack will be used for each particle. :type texture_stack: TextureStack

acceleration_max = Vector(1, 1) class-attribute instance-attribute #

acceleration_min = Vector() class-attribute instance-attribute #

color = None class-attribute instance-attribute #

lifetime = -1.0 class-attribute instance-attribute #

max_particles = 100 class-attribute instance-attribute #

spawn_cooldown = 0.1 class-attribute instance-attribute #

texture = None class-attribute instance-attribute #

texture_stack = None class-attribute instance-attribute #

velocity_max = Vector(1, 1) class-attribute instance-attribute #

velocity_min = Vector() class-attribute instance-attribute #