【发布时间】:2014-02-23 20:58:38
【问题描述】:
我有一个游戏,其中 MovieClip 的 y 坐标发生变化(我的重力实现),并且角色经常从地面上掉下来(y 坐标增加得如此之多,以至于 MovieClip 只是跳过了使角色停止下降的坐标)。为了解决这个问题,我想也许角色的 y 坐标应该一次增加 0.1,直到角色在 while 循环中到达特定点。我试过这样的事情:
var yToGo = char.y + jumpPow; //jumpPow is something that increases that makes the character "fall" when not touching the ground.
while(char.y !== yToGo)
{
char.y += char.y < yToGo ? 0.1 : -0.1;
for(i = 0; i < fallingBlocks.length; i++) //fallingBlocks is basically the array that holds "ground"
{
if(charTouchingFallingBlock(i)) //checks if the character is touching any of the grounds
{
jumping = false; //Makes character stop falling
char.y = fallingBlocks[i].y; //Makes character go to y of the ground it's touching
break;
}
}
}
charTouchingFallingBlock 函数通过将整数作为参数之一来检查角色是否触地,它看起来像:
function charTouchingFallingBlock(i)
{
return jumpPow >= 0 && fallingBlocks[i].hitTestPoint(char.x, char.y, true) && char.y <= fallingBlocks[i].y);
}
这几乎不起作用,因为 SWF 应用程序有时会在角色“下落”并且最近的地面略低于角色时冻结。如您所见,我基本上让角色向 y 坐标移动并在到达时停止,或者在接触地面时停止(阻止角色穿过地面)。
我的循环是否有问题,或者是否有一个内置函数的库可以为我执行此操作?
【问题讨论】:
标签: actionscript-3 actionscript