Well, the object won’t do anything on its own. You need to keep it updated.
So, first create an instance of your class, you can pass all the needed variables to it at this time, like size, lifetime etc…
As a tip you can create the physical object first, then pass that to the class, if the class needs to get info about the scene, it can get them from the physical object
class Particle(object):
def __init__(self,game_object,lifetime):
self.game_object=game_object
self.lifetime = lifetime
self.scene = self.game_object.scene
self.ending = False
On the particle manager you need:
def manage_particles(cont):
own = cont.owner
if "ini" not in own:
own['particles'] = []
particle_object = own.scene.addObject("particle",own,0)
own['particles'].append(Particle(particle_object,60))
own['ini'] = True
- object is the class instance, it’s automatically passed
Next add that to some kind of particle manager. It can just be an update script attached to an object in the scene.
In the particle you need an update function:
class Particle(object):
...
def update(self):
self.lifetime -= 1
if self.lifetime <= 0:
self.ending = True
else:
self.do_stuff()
and you need the manager to update it:
def manage_particles(cont):
own = cont.owner
...
if own['particles']:
next_generation = []
for particle in own['particles']:
if not particle.ending:
next_generation.append(particle)
particle.update()
else:
particle.game_object.endObject()
You’ll need to run this code every frame or as often as you intend to update the particles. When particles run out of steam they won’t be carried forward to the next generation, and so they will be lost. (I’m pretty sure the instance gets destroyed, but maybe someone with better knowledge can tell me about that. Does it need to be destroyed manually, or will it just go away once there are no active references to it?)
Alternatively, as monster suggests you can use the BGE’s built in structure to manage particles in the normal way.
p.s. if you are going to start down the dark path it might be better to organize your particle manager as a class/object too. Then your main game_loop can update the particle manager object each tic, and the manager will update all its particles in turn. The game_loop can also be a class, and so on.