Game Development Reference
through the constructor once, relying on Flash to do it for us. Once
it is created, the constructor will throw an error from here on out.
The other addition we made is in case this document is loaded
into another SWF. If this game is loaded into a container that has
the ability to load and unload it multiple times, it
the Singleton cleanup by itself once it is removed from the stage.
This will prevent persistence of the Singleton in memory.
For another example of a Singleton in practice, refer to Chapter 8
the same pattern. These types of controllers, or
candidates for Singletons because they need to be easily accessible
from anywhere in your game.
If you are interested in learning more about design patterns to use
in your game development, there are links to good articles and
other topics on this topic
swebsite, www.flashgamebook.com .The
bottom line to remember is to always do what makes sense for
your situation and don
t go overboard with a solution that isn
applicable to what you
re doing. Ultimately, if your game is no fun,
no one will care that it is a perfectly implemented, flawlessly
designed model-view-controller pattern. Learning to program well
and effectively is a journey, and given the ever-changing landscape
of new languages, technologies, and platforms, no one will ever
reach a destination where they can say
might, but they
ll be left in the dust pretty quickly by everyone else.