advantages and disadvantages to having multiple loops flash
What are the advantages and disadvantages of having just one ma开发者_运维百科in loop and having a main class control individual objects on your stage, in oppose to having each individual object have its own loop and giving it the responsibilities of doing what ever it has to do on its own. What are consider best practices.
I don't know that "loop" is necessarily the right term here.
If you're talking about having a single DocumentClass that controls everything versus having a lot of classes (ie most of your major visual elements have their own classes with their own internal logic) then it is to some degree a matter of personal preference. However, generally speaking it's probably a good idea to separate your concerns as much as possible.
If you have a main document with, let's say, two characters - the player and an enemy monster - then you don't want to write all of your code on the document. Instead, you want the player and the monster to each have their own internal code. That way it's easy to later add another monster, for instance - does that make sense?
Rather than writing out all of the complex logic for each monster twice, you simply create a Monster class and then you know that it'll always react the same way, even if you put a million on the stage. And you only have to write the code once.
Does that make sense? It's kind of a vague question, but yeah - if you want to take a "programmer's" approach it's always best to write the least amount of code possible. In the case of Flash architecture, that frequently means letting your code live where it can be most efficiently reused.
I hope that helpS!
I tend to copy the model used in XNA framework for C#. That is I have a class that has one main update loop. It then loops through all the entities and calls their update loop.
Using a single main loop definitely makes it easier for you to add pause/unpause functionality. In general, non-Flash game engines have a single main game loop. Individual objects have update()
and draw()
functions which are called from the main loop.
Here's a good explanation of the concept for Flash: Pause Your Game in Flash AS3.
精彩评论