AS2 Best way to decrease lag when dealing with several movieclips with onEnterFrames

后端 未结 1 1061
轻奢々
轻奢々 2021-01-27 06:24

As the title states, I\'m wondering what the best way to handle several movieclips on the stage at one time, each with their own onEnterFrame functions. Lets say we have 50 enem

相关标签:
1条回答
  • 2021-01-27 07:07

    Each onEnterFrame listener creates new event objects, so the more onEnterFrame listeners you have the more objects gets created each frame. And in AS2 object creation is pretty slow.

    So, one optimization to consider is to just register one onEnterFrame event and then from that "main" onEnterFrame loop through all enemies etc. and call an update function on each instance.

    It is also a good idea from a code structure point of view since you now only have one piece of code running each frame. It makes it easier to see what is actually running each frame. And to pause the game you could simply stop the main onEnterFrame and the whole game would stop.

    0 讨论(0)
提交回复
热议问题