Tuesday, February 23, 2010

Scene Manager for Rusher Game Framework

The scene manager for Rusher Game Framework is now complete. It makes use of Rusher's Command Utility to achieve scene transitions, i.e. intro and outro.

One engine core contains one scene manager, which is accessed from the Engine.sceneManager property. The SceneManager.setScene() method sets the current scene for the engine core. The scene transition is handled by the Scene.introCommand and Scene.outroCommand properties. When the engine core is switching from scene A to scene B, the outro command of scene A is executed, the intro command of scene B is executed, and then finally the scene transition is complete. This scene transition command structure was inspired by Progression Framework.

Here are some code snippets for the scene transition. You can view the final result here. Click the black square and watch the scene manager do its work.

The document class is quite simple. It starts up the engine core and sets the scene to a HomeScene object.

And below is the code for the HomeScene class. It extends the Scene class and assigns two command objects to the introCommand and outroCommand properties. The _block property simply holds a reference to a Sprite with a square appearance.

The intro command makes the block fade in from zero alpha and a random position to another random position, while the outro command fades out the block to zero alpha and another random position.

The AddChild command adds the block to the container sprite. The TweenNanoFrom command is making use of the from() method of the TweenNano class from GreenSock Tweening Platform. The Trace, SetProperties, AddEventListener, RemoveEventListener commands do what their name suggest: tracing messages, setting properties, adding event listeners, and removing event listeners, respectively.

When the block is clicked, the scene tells the SceneManager to switch to another scene, in this case, still another HomeScene instance.

There are more commands integrated with GreenSock Tweening Platform not shown in this example: TweenLiteFrom, TweenLiteTo, TweenMaxFrom, and TweenMaxTo. I believe their names tell you everything about what they do.

I'm quite happy with how the Command Utility turned out. Managing how the program flow by using parallel and serial commands is very easy, and, more importantly, it is achieved with simple, clean, and readily maintainable code.

No comments: