Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码有问题。为什么这个动画仍然加速。[在此链接中是代码][1]
[1]:http: enter code here //jsfiddle.net/74j0u5zf/4/
enter code here
因为您的多个if语句可以执行每个循环。如果 x == 500,它也 > 0。
if
您的gameLoop()功能可以大大简化。
gameLoop()
function gameLoop() { renderer.render(stage); cat.x = cat.x + moveX; if (cat.x <= 0 || cat.x >= 500) { moveX = -moveX; } requestAnimationFrame(gameLoop); }
http://jsfiddle.net/74j0u5zf/5/