【问题标题】:why the animation is accelerating为什么动画正在加速
【发布时间】:2017-08-06 06:32:10
【问题描述】:

我的代码有问题。为什么这个动画仍然加速。 [在此链接中是代码][1]

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

【问题讨论】:

    标签: javascript svg pixi.js grafika


    【解决方案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);
    }
    

    http://jsfiddle.net/74j0u5zf/5/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-21
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多