我正在制作一个游戏,屏幕顶部的昆虫落下。游戏的目的是杀死这些昆虫。我已经为这些昆虫的移动方式做了一个代码,但是问题似乎是它们似乎以不平滑的方式旋转。他们抽搐! 这是代码:如何让我的对象在我的游戏中更平滑地旋转?
else // Enemy is still alive and moving across the screen
{
//rotate the enemy between 10-5 degrees
tempEnemy.rotation += (Math.round(Math.random()*10-5));
//Find the rotation and move the x position that direction
tempEnemy.x -= (Math.sin((Math.PI/180)*tempEnemy.rotation))*tempEnemy.speed;
tempEnemy.y += (Math.cos((Math.PI/180)*tempEnemy.rotation))*tempEnemy.speed;
if (tempEnemy.x < 0)
{
tempEnemy.x = 0;
}
if (tempEnemy.x > stage.stageWidth)
{
tempEnemy.x = stage.stageWidth;
}
if (tempEnemy.y > stage.stageHeight)
{
removeEnemy(i);
lives--;
roachLevel.lives_txt.text = String(lives);
}
}
}
} ,我遇到的是一些昆虫沿着屏幕的边缘去另一个问题。用户几乎可以杀死他们,因为他们一半的身体在屏幕上,而另一半则关闭。我可以让它们从边缘移开一点,就像偏移一样?谢谢!
你每一帧这样做呢? – Pier
我正在对数组中的每个对象执行此操作。没有动画,全部由动作脚本提供动力 – user2896120
如果在每个帧处更改某些内容(x,y,旋转),动画也可以通过动作发生。您错误地认为只有在时间轴上使用关键帧等时才会发生动画。这里有一本很好的书,只是用AS3中的代码来动画的东西。 http://www.amazon.com/Foundation-Actionscript-3-0-Animation-Making/dp/1590597915 – Pier