topical media & game development
#graphic-player-10-cube-be-nascom-flash10-tests-CubeTestZsorting.ax
#graphic-player-10-cube-be-nascom-flash10-tests-CubeTestZsorting.ax
[swf]
[flash]
flex
package be.nascom.flash10_tests{
import be.nascom.flash.threeD.MouseRotator;
import be.nascom.flash10_tests.widgets.CubeSideMaterial;
import be.nascom.flash10_tests.widgets.MouseRotationTracer;
import be.nascom.flash10_tests.widgets.SimpleCube;
import be.nascom.flex.component.FlexSimpleTraceBox;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
public class @ax-graphic-player-10-cube-be-nascom-flash10-tests-CubeTestZsorting extends AbstractFP10Test{
protected var _cube:SimpleCube;
protected var _mouse_rotator:MouseRotator;
public function @ax-graphic-player-10-cube-be-nascom-flash10-tests-CubeTestZsorting(){
super();
FlexSimpleTraceBox.trace("@ax-graphic-player-10-cube-be-nascom-flash10-tests-CubeTestZsorting()");
}
override public function run():void{
FlexSimpleTraceBox.trace("CubeTest.run()");
createCube();
startRotateCube();
root.transform.perspectiveProjection.projectionCenter = test_holder.localToGlobal(new Point(400,400));
}
protected function createCube():void{
removeCube();
_cube=new SimpleCube(getMaterials());
_cube.x=400;
_cube.y=300;//because the holder is at 100
this.test_holder.addChild(_cube);
}
protected function getMaterials():Array{
var materials:Array=new Array(6);
var i:uint;
for(i=0;i<6;i++){
materials[i]=new CubeSideMaterial(200,200,i);
}
return materials;
}
protected function rotateCube(e:Event):void{
//trace("CubeTest.rotateCube()");
_cube.rotate(_mouse_rotator.x_rotation_speed,_mouse_rotator.y_rotation_speed,_mouse_rotator.z_rotation_speed);
}
protected function startRotateCube():void{
trace("CubeTest.startRotateCube()");
_mouse_rotator=new MouseRotator(0,0,800,800,5);
stage.addEventListener(MouseEvent.MOUSE_MOVE,_mouse_rotator.update);
addEventListener(Event.ENTER_FRAME,rotateCube);
}
protected function stopRotateCube():void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,_mouse_rotator.update);
removeEventListener(Event.ENTER_FRAME,rotateCube);
}
protected function removeCube():void{
if(_cube!=null){
_cube.destroy();
if(test_holder.contains(_cube))test_holder.removeChild(this._cube);
}
}
override public function destroy():void{
removeCube();
stopRotateCube();
FlexSimpleTraceBox.trace("CubeTest.destroy()");
}
//possibility for developer to document findings, important items to note etc. Use HTML.
override public function getNotes():String{
var note:String="";
note+="<ul>";
note+="<li>Sorting is achieved by adjusting the stack depth of the items</li>";
note+="<li>This example still positions the sides with x,y,z and rotation x,y and z.</li>";
note+="<li>[Sprite].transform.getRelativeMatrix3D(parent).position.z</li>";
note+="<li> -Is the magic function which returns a z depth relative to a 'container'</li>";
note+="<li>this is followed by a simple loop every frame, which removes and adds the children in the appropriate order</li>";
note+="</ul>";
return note;
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.