topical media & game development
#graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest.ax
#graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest.ax
[swf]
[flash]
flex
package be.nascom.flash10_tests{
import be.nascom.flash10_tests.widgets.NestedPerspectiveMenuItem;
import be.nascom.flex.component.FlexSimpleTraceBox;
import be.nascom.util.MathFunctions;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
public class @ax-graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest extends AbstractFP10Test{
protected var _menu:Sprite;
public function @ax-graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest(){
super();
FlexSimpleTraceBox.trace("@ax-graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest()");
}
override public function run():void{
FlexSimpleTraceBox.trace("@ax-graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest.run()");
renderGrid();
root.transform.perspectiveProjection.projectionCenter = test_holder.localToGlobal(new Point(400,400));
rotateRandom();
}
protected var _items:Array;
protected function renderGrid():void{
var size:uint=100;
_menu=new Sprite();
_menu.x=200;
_menu.y=100;
var total:uint=5;
var total_size:uint=size*total;
var offset:Number=-total_size/2;
_items=new Array();
var item:NestedPerspectiveMenuItem;
for(var i:uint=0;i<total;i++){
for(var j:uint=0;j<total;j++){
item=new NestedPerspectiveMenuItem(size,size,(i*total)+j);
item.x=j*size;
item.y=i*size;
// item.x=offset+j*size;
// item.y=offset+i*size;
_menu.addChild(item);
_items.push(item);
}
}
//_menu.x+=Math.abs(offset);
//_menu.y+=Math.abs(offset);
test_holder.addChild(_menu);
}
protected function rotateRandom():void{
//_menu.rotationX=-45+Math.random()*90;
//_menu.rotationY=-45+Math.random()*90;
addEventListener(Event.ENTER_FRAME,rotateMenu);
}
protected function rotateMenu(e:Event):void{
//_menu.rotationX=_menu.mouseX
//_menu.rotationY=
if(_menu==null)return;
if(_menu.getBounds(test_holder).contains(test_holder.mouseX,test_holder.mouseY)){
//trace(test_holder.mouseX+","+test_holder.width);
//trace(test_holder.mouseY+","+test_holder.height);
_menu.rotationX=MathFunctions.map(_menu.mouseX,0,_menu.width,-20,20);
_menu.rotationY=MathFunctions.map(_menu.mouseY,0,_menu.height,-20,20);
//_menu.rotationX=MathFunctions.map(test_holder.mouseX,0,test_holder.width,-45,45);
//_menu.rotationY=MathFunctions.map(test_holder.mouseY,0,test_holder.height,-45,45);
}
}
override public function destroy():void{
removeEventListener(Event.ENTER_FRAME,rotateMenu);
FlexSimpleTraceBox.trace("@ax-graphic-player-10-cube-be-nascom-flash10-tests-NestedPerspectiveTest.destroy()");
var tot:uint=_items.length;
for(var i:uint=0;i<tot;i++){
NestedPerspectiveMenuItem(_items[i]).destroy();
_items[i]=null;
}
_items=null;
}
//possibility for developer to document findings, important items to note etc. Use HTML.
override public function getNotes():String{
var note:String="How about nested perspective? how does that work?...";
note+="<ul>";
note+="<li>...as expected. The buttons are created into a parent sprite.</li>";
note+="<li>The parent sprites X and Y rotation changes based on mouse position</li>";
note+="<li>On mouseover, each button changes their Z from 0 to 50</li>";
note+="<li>It's a bit jumpy, as the mouse can sometimes jump off the 'hotspot' when the z changes.</li>";
note+="<li>Would be nice to add a quick tween...</li>";
note+="<li>Would be nice to add a mask that 'cuts' the shadows at the grid edges...</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.