Simple away3D tutorial with Flex + FlashDevelop

Kali ini penulis akan memberikan sebuah tutorial sederhana tentang engine 3D untuk flash yaitu away3D.

buat yang belum tahu apa itu away3D bisa cek disini . Away3D adalah sebuah engine 3D untuk flash.

ok langsung saja kita mulai.

  1. Pertama download Flash develop disini, Adobe Flex SDK disini dan away3D disini.
  2. Install Flex Develop dan Flash Develop.
  3. Extract Away3D.
  4. Mulai New Project pada Flash Develop,lalu kita atur classpathnya klik Project lalu pilih properties -> klik tab classpaths -> pilih folder hasil extract tadi. 
  5. Setelah itu buka file Main.as dan ketik coding dibawah ini

    fpackage
    {
    import flash.display.Sprite;
    import flash.events.Event;
    import away3d.materials.*;
    import away3d.materials.utils.*;
    import away3d.primitives.*;
    import away3d.cameras.*;
    import away3d.containers.*;
    import away3d.core.utils.*;
    import away3d.core.render.*;
    import away3d.lights.*;

    import flash.media.*;
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;
    import flash.ui.*;
    import flash.utils.getTimer;
    import flash.utils.Timer;
    /**
    * ...
    * @author Javax
    */
    public class Main extends Sprite
    {
    [Embed(source='../free-grass-texture.jpg')] private var grassTex:Class;
    [Embed(source = '../woodcrate.jpg')] private var woodTex:Class;
    private var cam:HoverCamera3D;
    private var landscape:Cube;

    /**
    * The scene object used in the template.
    */
    public var scene:Scene3D;
    public var view:View3D;

    /**
    * Creates a new Template object.
    */

    private var up:Boolean = false;
    private var down:Boolean = false;
    private var right:Boolean = false;
    private var left:Boolean = false;
    private var timePassed:int;
    private var lastTimed:int;

    public function Main():void
    {
    if (stage) init();
    else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void
    {
    removeEventListener(Event.ADDED_TO_STAGE, init);

    //init scene
    scene = new Scene3D();

    cam = new HoverCamera3D();
    cam.zoom = 11;
    cam.focus = 80;
    cam.distance = 2000;
    cam.targetpanangle = 45
    cam.targettiltangle = 20;

    //init view
    view = new View3D({scene:scene,camera:cam});
    /* view.scene = scene;
    view.camera = cam;*/

    //center view to stage
    view.x = stage.width/2;
    view.y = stage.height/2;
    view.x = 350;
    view.y = 230;
    view.renderer = Renderer.INTERSECTING_OBJECTS;

    landscape = new Cube({material:new BitmapMaterial(Cast.bitmap(grassTex)), name:"cube",width:500, height:130, depth:500, segmentsH:3, segmentsW:3, smooth:false});
    landscape.y = -40;
    landscape.x = 0;
    landscape.outline = new WireframeMaterial("black", {width:2});//outline size
    landscape.scaleX = 2;
    landscape.scaleZ = 2;
    //landscape.ownCanvas = true;
    scene.addChild(landscape);

    addChild(view);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
    addEventListener(Event.ENTER_FRAME, Render);

    }
    public function keyPressed(event:KeyboardEvent):void
    {
    switch (event.keyCode)
    {
    case Keyboard.UP :
    up = true;
    break;
    case Keyboard.DOWN :
    down = true;
    break;
    case Keyboard.RIGHT :
    right = true;
    break;
    case Keyboard.LEFT :
    left = true;
    break;
    }
    }

    public function keyReleased(event:KeyboardEvent):void
    {
    switch(event.keyCode)
    {
    case Keyboard.UP:
    up = false;
    break;
    case Keyboard.DOWN:
    down = false;
    break;
    case Keyboard.RIGHT:
    right = false;
    break;
    case Keyboard.LEFT:
    left = false
    break;
    }
    }

    public function Render(e:Event):void
    {
    timePassed = getTimer() - lastTimed;
    lastTimed += timePassed;

    cam.targetpanangle = (stage.stageWidth * .2 - stage.mouseX) * .2 - 360 * (timePassed/1000);
    cam.targettiltangle = (stage.stageHeight * .5 - stage.mouseY) * .5;

    /*-------------GAME LOGIC------------------------------*/

    if(left)
    {
    cam.targetpanangle += 80 * (timePassed/1000);

    }
    if(right)
    {
    cam.targetpanangle -= 80 * (timePassed/1000);
    }
    if(down)
    {
    cam.zoom--;

    }
    if(up)
    {
    cam.zoom++;
    }

    if(stage.mouseX >= 0 && stage.mouseX = 670 && stage.mouseX <= 700)
    {
    cam.targetpanangle -= 80 * (timePassed/1000);
    }

    cam.hover();
    view.render();
    }

    }

    }

Build dan jalankan, maka hasilnya seperti ini

Klik disini untuk melihat hasilnya http://filebin.gamedevid.org/f/100aj.swf

Control :
Up – Zoom in
Down – Zoom out

Download source code disini http://rapidshare.com/files/359294529/tutorialAway.rar.html atau http://filebin.gamedevid.org/get/100ai/tutorialAway.rar

5 comments

  1. UB · March 6, 2010

    mantap om😀

  2. thestudioindependent · March 6, 2010

    makasih om..^^

  3. chocorobokun · March 10, 2010

    wogh thx mantap tutorial nya om
    ditunggu tutorial selanjutnya😀

  4. thestudioindependent · March 10, 2010

    makasih om..ok dtunggu aja tutorial selanjutnya..

  5. Pingback: Simple ND3D tutorial with flex + flash develop « Thestudioindependent's Blog

Comments are closed.