Skip to content

Latest commit

 

History

History
96 lines (65 loc) · 3.02 KB

particles.rst

File metadata and controls

96 lines (65 loc) · 3.02 KB
.. module:: sdl2.ext.particles
   :synopsis: A simple particle system.

A simple particle system

A simple particle processing system. The :class:`ParticleEngine` takes care of creating, updating and deleting particles via callback functions. It only decreases the life of the particles by itself and marks them as dead, once the particle's life attribute has reached 0 or below.

.. attribute:: createfunc

   Function for creating new particles. The function needs to take
   two arguments, the ``world`` argument passed to :meth:`process()`
   and a list of the particles considered dead (:attr:`Particle.life`
   <= 0). ::

     def creation_func(world, deadparticles):
         ...

.. attribute:: updatefunc

   Function for updating existing, living particles. The function
   needs to take two arguments, the ``world`` argument passed to
   :meth:`process()` and a :class:`set` of the still living
   particles. ::

     def update_func(world, livingparticles):
         ...

.. attribute:: deletefunc

   Function for deleting dead particles. The function needs to take
   two arguments, the ``world`` argument passed to :meth:`process()`
   and a list of the particles considered dead (:attr:`Particle.life`
   <= 0). ::

     def deletion_func(world, deadparticles):
         ...

.. method:: process(world : World, components : iterable) -> None

   Processes all particle components, decreasing their life by 1.

   Once the life of all particle components has been decreased
   properly and the particles considered dead (life <= 0) are
   identified, the creation, update and deletion callbacks are
   invoked.

   The creation callback takes the passed world as first and the
   list of dead particles as second argument. ::

     def particle_createfunc(world, list_of_dead_ones):
         ...

   Afterwards the still living particles are passed to the update
   callback, which also take the passed world as first and the
   living particles as set as second argument. ::

     def particle_updatefunc(world, set_of_living_ones):
         ...

   Finally, the dead particles need to be deleted in some way or
   another, which is done by the deletion callback, taking the
   passed world as first and the list of dead particles as second
   argument. ::

     def particle_deletefunc(world, list_of_dead_ones):
         ...