Im making a transition from Java to Flash/Actionscript and Im having sort of a hard time figuring out where to write my code for my flash game loop(or engine) due to flash having “frames” unlike Java.
Am I able to put the loop inside the Document class even having like game menus in the game? I havent found a way to put it in there without it always running when the flash application begins.
Or should I just have the game loop called every frame? For instance, frame 4 will be level 1 and so the engine will be called out there. And frame 5 will be level 2 and ill call a different instance of the game engine there. Is that possible to do that?
Im just having a difficult time due to the “frames”. So where would be the best place to put the game loop?
Thank you!
You will quickly learn to avoid the pitfalls of frames if you’re a serious Java engineer. In your document class, you can create a main-game loop by listening for Event.ENTER_FRAME:
You can stop the loop similarly be removing the event listener.
For more complex games, people commonly need to create more than one ENTER_FRAME listener. In this case, it is often more efficient to use a ‘ticker’ or some other device that minimises the number of event constructions by the player.
Hope this helps,
Alec