I present in this article 3 classes that I use regularly in my game development process. Those classes can be used for free in any project.
I've been developing social games for major U.S. companies over the passed years and collected more than 500 reusable classes from those projects. Some of those classes are used on every projects and I'd like to share in this article three of those that you can of course use for free in your projects. I'll explain how to use them and also describe why they are so helpful in my developement flow. Those classes can be used with Flash or Flex. Because those 3 classes provide a non intrusive and unique functionality, they are treated as Singleton (I make this distinction because writting singleton class is more of an exception for me than a rule).
An automated debug console which allows you to run debug code, trace results, run cheat codes, etc.
Let's try the console in this little movie. Press "`" to activate the console. Then type "showMovies" to show the hidden movies or type "changeSpeed" with an int parameter (add a space between command and parameters and in between parameters) to change the speed value. The 'changeSpeed' action is registered with one required parameter. If you do not add a valid parameter the console will show you the error. You can use as well the command "hideMovie" with is set with 3 optional parameters. If no parameters are passed all movies show up but if you set any parameter to zero the corresponding movie will be set invisible. These commands are called "action" and can be registered with the console at anytime and removed at anytime too. You can also type "help" to get a list of available commands and required parameters if any. Type exit to close the console or press "`" again.
The code used to set this console was very simple:[as]import ASWC.components.DebugConsole;
In this example the console was completely open, meaning you could use it
freely. Perfect when your game is still in developement. If you are in QA phase
with an already live game you might want to password protect the console. You do
this by passing a password in the console:
In production version you disable completely the console by calling:
The reason I use this console on all my game projects is because I can set
easily test cases during the developement process and I can also set easily
cheat codes during the QA process. Whether I test locally or in live version I
can always access my console and run all the test I want and check the results.
It saves me a lot of developement time, the QA people can request whatever cheat
code they want since it's very easy to set new console actions I'm not really
wasting time doing it. Also even if the game goes live I can still activate the
console if a bug was overlloked and I need to run additional tests. That class
is for me a time saver but also a tool that aloows me to communicate better
with other people involved in the project.
The Tracer class is plugged and included with the DebugConsole class but you can use it on its own. It is a 'super' trace class. Now why would I need another type of trace class? For two main reason:
For complex developement and/or team developement it is recommended to use and create a Logger type of class as in the Flex framework for example. I have done that in the past too but I always wanted something more universal and simple. That is why I created this class and I use it now in all my projects. Main features are:
Use the DebugConsole in this example and type "dump" to show all the traces:[as]Tracer.useOutput = false; Tracer.show(speed_txt.text, "speed", this); Tracer.reveal(mc1_mc);[/as]
Note how using Tracer.reveal() shows all property of the object including dynamic ones. You could of course use this on an array, object, dictionary and all contained object will be revealed.
This class was especially made for games but can be used for any type of application really. It manages and plays sounds externally loaded or stored in libraries (Flex/Flash). It really provides the basic needs of sound playing in games and still allows you to include your own code for specific functionality if needed. Implementing hundreds of sounds in a game including sound tracks, music tracks, sound effects takes me about one hour for a very complex game. It doesn't get more efficient than that. Main Features:
Try this little example which includes the 3 type of sound the SoundManager can manage, for the purpose of this example the SOUNDTRACK playing stops the LOOPING_SOUNDTRACK and vice versa:
Some relevant code. Registering sounds and playing them:[as]import ASWC.media.SoundManager;
It's quite obvious why this class is saving me so much time. You can see that that class uses string names to reference sounds. Those names can easily be setup as static const somewhere (even coming from external data) and played directly that way. A really simple example would be for a simple MouseEvent.CLICK where MouseEvent.CLICK is used as a sound name directly and all that is left to do in the MouseEvent listener is to use SoundManager.getInstance().play(e.type);. note that the SoundManager does not throw error if you try to play a sound that does not exist. There is also two master volume that you can use. One linked to the SOUND type and one linked to SOUNDTRACK and LOOPING_SOUNDTRACK. Those master volume affect the sound volume as it was set. Let's say you have two sound volumes set respectively at 0.4 and 0.8. When the master volume is at 0 both sound volume are at 0, when the master volume is at 1 both sound volume are at 0.4 and 0.8. If you have a mute button in your game you could mute all sounds easily by setting the two master volume to 0 or use directly the pauseAll() method. Check the docs for more in depth covering of that useful class.
That's it for this little article showing 3 useful classes that save me a lot of time on a daily basis and maybe they will save you some time as well!