单击时使角色向上移动

时间:2016-03-06 13:49:42

标签: javascript

我正在制作类似Flappy Bird的游戏。单击浏览器窗口时,该字符应向上移动,但我的代码不起作用。以下是相关的代码行:

var dudeYSpeed = 0;
var dudeXSpeed = 0;
var dudeJumping = false;
var jumpSpeed = -3;

if (mouseDown && dudeJumping === false){
    dudeJumping = true;
    dudeYSpeed = jumpSpeed;
} 
else {
    translateY += dudeYSpeed;
    dudeYSpeed += gravity;
    dudeJumping = false;
} 

translateX += dudeXSpeed;

1 个答案:

答案 0 :(得分:0)

如果translateY为真,您只会更新dudeYSpeeddudeJumping。无论输入是什么,您都应该在每一帧中更新这些变量。