简体   繁体   English

为什么动画在加速

[英]why the animation is accelerating

I have problem with my code. 我的代码有问题。 Why this animation still accelerates. 为什么此动画仍会加速。 [in this link is code ][1] [在此链接中的代码是[1]

[1]: enter code here http://jsfiddle.net/74j0u5zf/4/ [1]: enter code here http://jsfiddle.net/74j0u5zf/4/

Because more than one of your if statements can execute each loop. 因为您的多个if语句可以执行每个循环。 If x == 500, it is also > 0. 如果x == 500,则它也> 0。

Your gameLoop() function can be greatly simplified. 您的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/ http://jsfiddle.net/74j0u5zf/5/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM