topical media & game development
animation-ch15-Perspective1.ax
animation-ch15-Perspective1.ax
[swf]
[flash]
flex
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class @ax-animation-ch15-Perspective1 extends Sprite
{
private var ball:animation_ch15_Ball;
private var xpos:Number = 0;
private var ypos:Number = 0;
private var zpos:Number = 0;
private var fl:Number = 250;
private var vpX:Number = stage.stageWidth / 2;
private var vpY:Number = stage.stageHeight / 2;
public function @ax-animation-ch15-Perspective1()
{
trace("hello");
init();
}
private function init():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
ball = new animation_ch15_Ball();
addChild(ball);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onEnterFrame(event:Event):void
{
xpos = mouseX - vpX;
ypos = mouseY - vpY;
var scale:Number = fl / (fl + zpos);
ball.scaleX = ball.scaleY = scale;
ball.x = vpX + xpos * scale;
ball.y = vpY + ypos * scale;
}
private function onKeyDown(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.UP)
{
zpos += 5;
}
else if(event.keyCode == Keyboard.DOWN)
{
zpos -= 5;
}
}
}
}
(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.