vivo
vivo

Reputation: 26

AS3 performance difference between function and events

I working on a game project in Flash AS3.

I need to pass data from one class (Game) to other class objects (Ships) on EnterFrame and performance is starting to be a issue. I was wondering is there a difference in performance between calling to the Ship a direct function or dispatching an event which the Ship can listen.

another question is where should I put the enterframe function. Is it better to use only one enterframe function and call the methods \ dispatch events from there, or it will be wiser to put the enterframe in the different objects (Ships)? note: some Ships are inactive most of the time.

Hope I managed to explain myself.

Thanks,

Vivo

Upvotes: 1

Views: 522

Answers (1)

dain
dain

Reputation: 6689

It's definitely cheaper to call functions directly rather than having to go through the event dispatch / listen chain.

It's tricky how many EnterFrames you should have, generally speaking it's better to have as few as possible, but if you have to dispatch tons of events you're better off having a few more – that being said if you can do it with direct method calls from one central EnterFrame loop that's the best.

Also if your Ships are inactive most of the time then you shouldn't have an EnterFrame running on each.

Upvotes: 1

Related Questions