【发布时间】:2014-01-16 14:58:57
【问题描述】:
按几次启动/重启按钮,您会注意到速度增加了。这并不意味着,速度应该重置为“5”。不知道怎么回事。
开始/重置按钮的代码在 Fiddle 的底部:
//Start game function + button
function resetGame() {
ball.x = board.width/2;
ball.y = board.height/2;
ball.xSpeed = 5;
ball.ySpeed = 0;
player1.score = 0;
player1.newScore = false;
player2.score = 0;
player2.newScore = false;
}
startButton.onclick = function() {
startButtonText.innerHTML = "Restart game";
resetGame();
renderPresentation();
animate(step);
};
我尝试在调用之前停止动画:
startButton.onclick = function() {
startButtonText.innerHTML = "Restart game";
resetGame();
renderPresentation();
var rid = animate(step); //animate is window.requestAnimationFrame()
window.cancelAnimationFrame(rid);
animate(step);
};
我已经盯着我的代码太久了,有人能快速看一下吗? 谢谢!
【问题讨论】: