Playing with Away3D
I have just spent a couple of hours last night getting to grips with Away3D. I just created a little demo that creates a few spheres and then adds an ENTER_FRAME event listener and responds to mouse movement.
You can download the whole thing here: http://harry-northover-code-store.googlecode.com/files/Away3DBasics.zip
Here is a screene:
And here’s 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 | package { import away3d.cameras.HoverCamera3D; import away3d.containers.View3D; import away3d.primitives.Sphere; import flash.events.MouseEvent; import flash.display.Sprite; import flash.events.Event; import caurina.transitions.Tweener; public class Away3DBasics extends Sprite { public var stageHeightCenter:uint = stage.stageHeight / 2 - 100; public var stageWidthCenter:uint = stage.stageWidth / 2 + 100; public var cam:HoverCamera3D = new HoverCamera3D( { zoom:1, focus:200 } ); public var view:View3D = new View3D( { x:stageWidthCenter, y:stageHeightCenter, camera:cam } ); public function Away3DBasics() { cam.steps = 16; // Add the view to the stage. addChild(view); // Create 20 spheres. for (var i:uint = 0; i <= 20; i++) { var sphere:Sphere = new Sphere(); sphere.invertFaces(); sphere.x = Math.random() * 1000; sphere.y = Math.random() * 1000; sphere.z = Math.random() * 600; sphere.rotationX = Math.random() * 360; sphere.rotationY = Math.random() * 360; view.scene.addChild(sphere); } // Add Event listeners. this.addEventListener(Event.ENTER_FRAME, onRun); // Render the scene... cam.hover(); view.render(); } // This is the code for the ENTER_FRAME event. private function onRun(evt:Event):void { cam.rotationX = Math.random() * 360; cam.rotationY = Math.random() * 360; cam.rotationZ = Math.random() * 360; cam.pan(Math.random() * 360); Tweener.addTween(cam, { zoom: (stage.mouseY / stage.stageHeight) * 4 + 0.5, time:0.1, transition:"easeInOutExpo" } ); cam.hover(); view.render(); } } } |
There you go! I will be doing a lot more stuff with Away3D so keep an eye out!
Harry.









0 comments
Kick things off by filling out the form below.
Leave a Comment