ISOMetric
From WikiFlashed
An example of a isometric environment in AS3. This can be used in a multiplayer gaming server such as Smartfox Server.
I don't think I will release this isometric engine for free in any time soon, but you can check out the progress of games using it soon on this page.
Contents |
Concept
The concept used is very similar to the popular AS3 ISO Library out there. For fast performance in Flash, you just have to do one thing: Bitmap Draw!
I have created a nice decorator wrapping mechanism for ISO objects so that you can wrap as many attributes and varying functionalities to a ISO object as you can. For example, a jumping dog and a crawling snake has varying functionalities where one can jump() and one crawl().
Author
- WikiFlashed
- http://www.wikiflashed.com
Demo Play
The demo can be played at http://download.davincikrypt.com/demo
Code Snippets
First of all, lets talk about the rendering engine. In order to sync time with the actual rendering, you need to track the lagged ms during rendering. This is just the idea, in real scenarios, there should never be timers with a delay of 1 ms.
public class QuartzEngine extends MovieClip { public static var FPS:Number = 62; protected static var quartzTimer:Timer; // Time Calculation Variables private var _period:Number = 1000 / FPS; private var _beforeTime:int = 0; private var _afterTime:int = 0; private var _timeDiff:int = 0; private var _sleepTime:int = 0; private var _overSleepTime:int = 0; private var _excess:int = 0; public function QuartzEngine():void { addEventListener(Event.ADDED_TO_STAGE, onAdded); } /* * On added to stage Event, starts preloader * @Event */ protected function onAdded(evt:Event):void { if(!quartzTimer) { quartzTimer = new Timer(1); quartzTimer.addEventListener(TimerEvent.TIMER, onQuartzEvent); quartzTimer.start(); } stop(); } /** * Pauses the timer rendering */ protected function pause():void { quartzTimer.stop(); } /** * Starts the timer rendering */ protected function start():void { quartzTimer.start(); } private function onQuartzEvent(evt:TimerEvent):void { _beforeTime = getTimer(); _overSleepTime = (_beforeTime - _afterTime) - _sleepTime; // LOGIC HERE ============================= render() // LOGIC END ============================== _afterTime = getTimer(); _timeDiff = _afterTime - _beforeTime; _sleepTime = (_period - _timeDiff) - _overSleepTime; if (_sleepTime <= 0) { _excess -= _sleepTime; _sleepTime = 2; } quartzTimer.reset(); quartzTimer.delay = _sleepTime; quartzTimer.start(); while (_excess > _period) { // Execute required commands if slept for too long // For debugging //render() _excess -= _period; } } protected function render():void { if(stage) { stage.dispatchEvent(new MWEvent(MWEvent.RENDER)); } }