Hi, folks !
I know my last post was taken a while, the sandwich course is really intensive. However I will try to post more article. I’ve made many experiments since two months that I would like to share : stuff on games engine and datastructure.
For this firts post of 2011 (already !), I will introduce the actionscript isometric library : as3isolib. There are two others actionscript isometric library : TheoWorlds and OpenSpace but they are not free !
We will create an isometric world and add random boxes, if you click on one it will be removed. The result.
The code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | package { import as3isolib.display.IsoView; import as3isolib.display.primitive.IsoBox; import as3isolib.display.scene.IsoGrid; import as3isolib.display.scene.IsoScene; import as3isolib.enum.RenderStyleType; import as3isolib.geom.IsoMath; import as3isolib.geom.Pt; import as3isolib.graphics.SolidColorFill; import eDpLib.events.ProxyEvent; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.events.TimerEvent; import flash.utils.Timer; public class Main extends Sprite { private const _CELL_SIZE:uint = 50; private var _grid:IsoGrid; private var _scene:IsoScene; private var _view:IsoView; private var _box:IsoBox; private var i:uint; private var _timerCreationBox:Timer; public function Main() { this.addEventListener(Event.ADDED_TO_STAGE, _init); } private function _init(evt:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE, _init); _grid = new IsoGrid(); _grid.setGridSize(10, 10, 1); _grid.showOrigin = false; _grid.cellSize = _CELL_SIZE; _scene = new IsoScene(); _scene.hostContainer = this; _scene.addChild(_grid); _view = new IsoView(); _view.setSize(800, 600); _view.centerOnPt(new Pt(200, 200, 0)); _view.addScene(_scene); this.addChild(_view); _timerCreationBox = new Timer(300, 0); _timerCreationBox.addEventListener(TimerEvent.TIMER, _createNewBox); _timerCreationBox.start(); this.addEventListener(Event.ENTER_FRAME, _ef); } private function _createNewBox(tEvt:TimerEvent):void { _box = new IsoBox(); _box.styleType = RenderStyleType.SHADED; var couleur:uint = Math.random() * 0xFFFFFF; var alpha:Number = Math.random(); _box.fills = [new SolidColorFill(couleur, alpha), new SolidColorFill(couleur, alpha), new SolidColorFill(couleur, alpha), new SolidColorFill(couleur, alpha), new SolidColorFill(couleur, alpha), new SolidColorFill(couleur, alpha)]; _box.setSize(_CELL_SIZE, _CELL_SIZE, _CELL_SIZE); _box.moveTo(_CELL_SIZE * Math.floor(Math.random() * 10), _CELL_SIZE * Math.floor(Math.random() * 10), 0); _box.id = "box" + i; ++i; _box.addEventListener(MouseEvent.CLICK, _deleteBox); _scene.addChild(_box); } private function _deleteBox(mEvt:ProxyEvent):void { mEvt.proxyTarget.removeEventListener(MouseEvent.CLICK, _deleteBox); _scene.removeChildByID(mEvt.target.id); } private function _ef(evt:Event):void { _scene.render(); } } } |
The _scene.render() function is really important : it updates the scene of all your graphical change !
Later it will be a post on Box2d, stay tuned !