【发布时间】:2017-08-06 06:32:10
【问题描述】:
我的代码有问题。为什么这个动画仍然加速。 [在此链接中是代码][1]
[1]:enter code herehttp://jsfiddle.net/74j0u5zf/4/
【问题讨论】:
标签: javascript svg pixi.js grafika
我的代码有问题。为什么这个动画仍然加速。 [在此链接中是代码][1]
[1]:enter code herehttp://jsfiddle.net/74j0u5zf/4/
【问题讨论】:
标签: javascript svg pixi.js grafika
因为您的多个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);
}
【讨论】: