init(s)
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
stage.frameRate = 100;
ball = new animation_ch19_Ball();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
vx = 300;
vy = -300;
addChild(ball);
time = getTimer();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
frame(s)
private function onEnterFrame(event:Event):void
{
var elapsed:Number = getTimer() - time;
time = getTimer();
vy += gravity * elapsed / 1000;
ball.x += vx * elapsed / 1000;
ball.y += vy * elapsed / 1000;
var left:Number = 0;
var right:Number = stage.stageWidth;
var top:Number = 0;
var bottom:Number = stage.stageHeight;
process
if(ball.x + ball.radius > right)
{
ball.x = right - ball.radius;
vx *= bounce;
}
else if(ball.x - ball.radius < left)
{
ball.x = left + ball.radius;
vx *= bounce;
}
if(ball.y + ball.radius > bottom)
{
ball.y = bottom - ball.radius;
vy *= bounce;
}
else if(ball.y - ball.radius < top)
{
ball.y = top + ball.radius;
vy *= bounce;
}
}
}
}