Be a Supporter!

Single event listener vs multiple

  • 169 Views
  • 4 Replies
New Topic Respond to this Topic
Mandaley
Mandaley
  • Member since: Mar. 8, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Single event listener vs multiple 2014-02-09 07:46:32 Reply

I'm making a Side Scroller Shooter game using AS3. Would there be that much of a difference in performance if I were to make each object such as bullets, player and enemies have their own OnEnterFrame event listener? Or, is it better to have them all under a single main OnEnterFrame listener, and have it loop through calling each object's action function? The game won't be a bullet hell so there won't be that many objects on the screen; nearly much like RaidenX for example.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Single event listener vs multiple 2014-02-09 08:01:25 Reply

At 2/9/14 07:46 AM, Mandaley wrote: Or, is it better to have them all under a single main OnEnterFrame listener, and have it loop through calling each object's action function?

this

Etherblood
Etherblood
  • Member since: Apr. 14, 2013
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to Single event listener vs multiple 2014-02-09 08:14:17 Reply

At 2/9/14 07:46 AM, Mandaley wrote: I'm making a Side Scroller Shooter game using AS3. Would there be that much of a difference in performance if I were to make each object such as bullets, player and enemies have their own OnEnterFrame event listener? Or, is it better to have them all under a single main OnEnterFrame listener, and have it loop through calling each object's action function? The game won't be a bullet hell so there won't be that many objects on the screen; nearly much like RaidenX for example.

I didn't make a as3 game with many objects on stage yet, so my answer might be inaccurate.

I'm pretty sure that if you encounter performance problems, it won't be because each object has it's own enter-frame-listener. (I still recommend to have an action function for each object and call it instead)
It's more likely to be because you have a lot movieclips on stage, and movieclips are (relatively) slow, but I think it shouldn't be a problem in your example.

The easiest way to find out if it'll work is to test it.
You might want to consider Blitting if you encounter performance problems, just ask if you do.

Mandaley
Mandaley
  • Member since: Mar. 8, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Single event listener vs multiple 2014-02-09 09:08:48 Reply

Appreciate the responses guys!
I'll be going with the single event.

HappyWhaleStudios
HappyWhaleStudios
  • Member since: Feb. 1, 2013
  • Offline.
Forum Stats
Member
Level 07
Game Developer
Response to Single event listener vs multiple 2014-02-09 19:35:09 Reply

Yeah, if you want to have something with a lot of instances, you definitely want to put it all on the same event handler. The most logical way to do that is to have an array of the objects of that instance and then run through a for loop and call a function that you would've had as its onEnterFrame function on each object.


BBS Signature