我的代码有问题。为什么这个动画仍在加速。 [在此链接中是代码] [1]
[1]:enter code here
http://jsfiddle.net/74j0u5zf/4/
答案 0 :(得分:1)
因为多个if
语句可以执行每个循环。如果x == 500,那么它也是> 0
您的gameLoop()
功能可以大大简化。
function gameLoop() {
renderer.render(stage);
cat.x = cat.x + moveX;
if (cat.x <= 0 || cat.x >= 500) {
moveX = -moveX;
}
requestAnimationFrame(gameLoop);
}