2017-03-15 9 views

답변

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/