【发布时间】:2015-09-24 14:31:33
【问题描述】:
我一直在为 Phaser 游戏苦苦挣扎。我一直在尝试制作我的游戏控件的移动版本,但由于某种原因,顺时针旋转我的汽车角色在达到 0、90、180 或 270 度后停止。逆时针工作就好了。
它是这样的:
//I made a turnSpeed dependant on the car's current speed
turnSpeed = speed / 6000;
//I then check for a boolean which is true if the button is touched
if (rightArrowLeftIsPressed)
{
playerCar.rotation += turnSpeed;
}
if (leftArrowLeftIsPressed)
{
playerCar.rotation -= turnSpeed;
}
//This will snap the car to 0, 90, 180 or 270 degrees if no button is pressed and the car is close to that rotation already
else
{
if (playerCar.rotation < 0.15 && playerCar.rotation > -0.15)
{
playerCar.rotation = 0;
}
if (playerCar.rotation > (Math.PI - 0.15) || playerCar.rotation < (-Math.PI + 0.15))
{
playerCar.rotation = Math.PI;
}
if (playerCar.rotation > -Math.PI / 2 - 0.15 && playerCar.rotation < -Math.PI / 2 + 0.15)
{
playerCar.rotation = -Math.PI / 2;
}
if (playerCar.rotation > Math.PI / 2 - 0.15 && playerCar.rotation < Math.PI / 2 + 0.15)
{
playerCar.rotation = Math.PI / 2;
}
}
有人知道为什么它会像那样限制顺时针旋转吗?
非常感谢。
【问题讨论】:
标签: javascript mobile rotation touch phaser-framework