Search code examples
performanceactionscript-3flashactionscriptmovieclip

Actionscript 3 how to move many object at once without lag


I have a simple question. I'm using actionscript 3.0 and Adobe flash professional cs6 to make a game. I want to keep it simple, clean, and not laggy, but for my game i need many (10-30) movieclips moving different ways at the same time on screen. I want to use time-based animation for the Event.ENTER_FRAME event, but I don't know whether having each individual (since they all inherent from a super-class that could do this) movieclip keep track of its own time and move itself that way, or have a manager class keep track of time and then call a function to all the movieclips with the time as a parameter. I want to know which one is faster in the end.


Solution

  • To add to the great answer linked above, you should carefully consider and plan what components of your game will require the most attention and optimization. Trying to optimize every aspect will become extremely cumbersome and hard to manage. In addition to this, certain types of optimization can not occur at the same time (e.g. you often cannot optimize for speed and memory consumption at the same time, because improving one will degrade the other).

    For example - if you know your game is going to have a lot happening on screen (lots of graphics and effects), then you should seriously consider a library that focuses on rendering performance, like Starling, which leverages the newer Stage3D APIs to improve drawing speed immensely.

    If in another example your game needs to make lots of measurements between objects and implement things like raycasting and pathfinding, then you should look at how to go about building a grid for your game that can most efficiently run these algorithms.

    As for cleanliness, specifically when it comes to your mention of Event.ENTER_FRAME, you should only implement one handler for this event in the main class of your game (or a similar handler class). Your actual game objects should be listed in an array in this class and the enterFrame handler should iterate over that array and call a function on each of them, i.e. update() or similar.