"Effect complete" callback

4 views
Skip to first unread message

Mike Wyatt

unread,
Feb 18, 2010, 1:00:13 AM2/18/10
to General discussion of the Lepton particle engine for Python
I've stolen the spectacular explosion effect from the splode2d.py
example and added it to my project. I've integrated it with my game's
entity system, meaning that once the explosion is complete I want to
remove it from the world.

I didn't see any sort of callback functionality in the Lifetime
controller, so I instead used Pyglet's clock functionality to schedule
the event.

This seems to work fine, but I'd like to make sure there isn't a
better way. Is there?

Casey Duncan

unread,
Feb 18, 2010, 11:42:57 AM2/18/10
to py-lept...@googlegroups.com
I think the answer depends on what you mean by "remove". Emitter
objects do have a TTL you can set to auto-remove them from their
parent group. I suspect this is not helpful though since for an
explosion the particles are all emitted instantaneously and not
steadily over time.

Before I can give an answer, here's some questions for you:

- Are you using separate group(s) for each explosion?
- If not, what is it you want to remove exactly?

-Casey

> --
> You received this message because you are subscribed to the Google Groups "General discussion of the Lepton particle engine for Python" group.
> To post to this group, send email to py-lept...@googlegroups.com.
> To unsubscribe from this group, send email to py-lepton-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/py-lepton-users?hl=en.
>
>

Mike Wyatt

unread,
Feb 19, 2010, 11:26:13 AM2/19/10
to General discussion of the Lepton particle engine for Python
I think I see the solution. I'm currently creating a new group for
each explosion, but it sounds like using a single persistent group for
all explosions would be better. I could then set time_to_live on each
explosion's individual emitter (to the same value as the particle's
lifetime). Or even better still, I could use the same emitter for all
explosions.

Is either of those options better than the other?

Casey Duncan

unread,
Feb 19, 2010, 11:51:40 AM2/19/10
to py-lept...@googlegroups.com
Yes, using a single group will be simpler and more efficient. This
will mean there are far fewer memory (re)allocations happening at
run-time. The only real reason to use multiple groups is so that you
can closely control the draw order or other drawing state for each
group independently.

Emitters are really cheap to create and destroy (certainly in relation
to groups), so its up to you whether you want to reuse them or throw
them away for each explosion. I think it would be cleaner and less
bug-prone to use a separate emitters for each explosion. Otherwise I
can imagine cases where the emitter is re-used before it has a chance
to finish emitting particles for the previous effect.

-Casey

Mike Wyatt

unread,
Feb 20, 2010, 12:22:08 AM2/20/10
to General discussion of the Lepton particle engine for Python
Thanks.

By the way, I'm really impressed with Lepton. It is a fantastic
library. Very Pythonic, easy to use, and fast. Keep up the good
work!

On Feb 19, 10:51 am, Casey Duncan <casey.dun...@gmail.com> wrote:
> Yes, using a single group will be simpler and more efficient. This
> will mean there are far fewer memory (re)allocations happening at
> run-time. The only real reason to use multiple groups is so that you
> can closely control the draw order or other drawing state for each
> group independently.
>
> Emitters are really cheap to create and destroy (certainly in relation
> to groups), so its up to you whether you want to reuse them or throw
> them away for each explosion. I think it would be cleaner and less
> bug-prone to use a separate emitters for each explosion. Otherwise I
> can imagine cases where the emitter is re-used before it has a chance
> to finish emitting particles for the previous effect.
>
> -Casey
>

Casey Duncan

unread,
Feb 20, 2010, 1:03:30 AM2/20/10
to py-lept...@googlegroups.com
Thanks! Keep us informed of your progress and feel free to post
examples of what you are doing as well.

-Casey

Reply all
Reply to author
Forward
0 new messages