views:

46

answers:

4

Hi, i'm curious about something. Let say we have 30 object in the code, and every object should be animated trough enter frame event. Which will be faster(in terms of memory execution) : to have just one event listener in the main object (for example) and to call object methods, or, to have separate event listener for every object? Thanks :) .

UPDATE: Well, actually, i need to monitor each object to find out when that object is on current frame, e.g. on end of animation, and than remove it from display list. What is the best way to that?

+1  A: 

You should try to use tweens instead of animating via ENTER FRAME event.

Animating on ENTER FRAME will cause tremendous lag, especially if you have lots of objects.

Checkout TweenLite: http://www.greensock.com/tweenlite/

diggersworld
I completely fail to see what you mean. Tweening is made on enter frame afaik, isn't it ? It's more a question of on _which_ enterframe you do it, I think.
Axelle Ziegler
@Axelle Ziegler: Tweening is generally **updated** on enterframe, but is framerate independant, which does improve overall performance (in the worst case scenario, a few frames are skipped, but your app doesn't slow down).
back2dos
A: 

Definitely to have just one event listener. The less listeners, the faster.

Raveline
A: 

As a rule of thumb, one listener is better, and will induce a more predictible behaviour.

That being said, it depends pretty heavily on what you're trying to do. You might not have to animate every object on every enter frame event, thus gaining performance further.

Axelle Ziegler
+1  A: 

For 30 objects, this doesn't really matter. Actually, in general it matters only little, since the bottleneck will always be rendering.
But to answer your question: Listeners are slow. For one notification to happen, an Event object needs to be created (allocation is generally quite expensive), and an untyped call of an anonymous function or a method closure needs to be done (which is signifficantly slower than calling a method on a strictly typed value).

back2dos