if(sprite.x - sprite.width / 2 > right ||
sprite.x + sprite.width / 2 > left ||
sprite.y - sprite.height / 2 > bottom ||
sprite.y + sprite.height / 2 < top)
重置出界對像:
if(sprite.x - sprite.width / 2 > right ||
sprite.x + sprite.width / 2 < left ||
sprite.y - sprite.height / 2 > bottom ||
sprite.y + sprite.height / 2 < top)
{
// 重置影片的位置和速度
}
屏幕環繞出界對像:
if(sprite.x - sprite.width / 2 > right)
{
sprite.x = left - sprite.width / 2;
}
else if (sprite.x + sprite.width / 2 < left)
{
sprite.x = right + sprite.width / 2;
}
if(sprite.y - sprite.height / 2 > bottom)
{
sprite.y = top - sprite.height / 2;
}
else if(sprite.y + sprite.height / 2 < top)
{
sprite.y = bottom + sprite.height / 2;
}
摩擦力應用(Correctly Way):
speed = Math.sqrt(vx * vx + vy * vy);
angle = Math.atan2(vy, vx);
if(speed > friction)
{
speed -= friction;
}
else
{
speed = 0;
}
vx = Math.cos(angle) * speed;
vy = Math.sin(angle) * speed;
摩擦力應用(Easy Way):
vx *= friction;
vy *= friction;
參考書目:Keith Peters.《Function Actionscript 3.0 Animation》.Friends of ED
沒有留言:
張貼留言