2011年9月2日 星期五

Designing the "engine"

After knowing how to invoke the application, it's time to have a detailed plan to get things done. The Canvas of the MXML should contain a UIComponent to hold the IsoView of the as3isolib. The view serves as a viewport which is movable around the scenes inside. To make it simple, there's always only one IsoScene inside the view. Inside the scene, there'll be a background, grid (for dragging) and buildings loaded from database.

All graphics are saved in separate SWF files. I prepared a class called "DynamicLoader" which looks up a class from different SWF files. For example, when I say I need the movie clip of a building called "building.WoodHouse", the instance will find and load the movie clip from "building.swf" and invoke a callback with the loaded MovieClip object. "DynamicLoader" is a singleton which contains a mapping indicating which prefix a SWF file represents.

To display buildings inside the scene, I created a class, IsoBuilding, a subclass of IsoBox. Its constructor requires a parameter which contains the attributes a building. When IsoBuilding is instantiated, it uses DynamicLoader to load the MovieClip and provides a callback to DynamicLoader. Once the loading is completed, the callback is invoked, the MovieClip will be added to an IsoSprite as an attribute of IsoBuilding object.

沒有留言:

張貼留言