这是我的JSFiddle:http://jsfiddle.net/Au6br/13/
问题在于,当我连续按下
keydown.up
时,玩家会多次跳跃。我想定义一个名为JumpCount
的变量,当角色跳跃时,如果该变量大于此值,则停止跳跃。 Character.prototype.Jump = function () { // Jumping
character.MaxJump += gravity;
character.y += character.MaxJump;
if (keydown.up) {
if (!character.jumping) {
character.jumping = true;
character.Pos = 4;
character.Row = 2;
character.h = 23;
character.MaxJump = -character.sp * 2.5;
}
}
if (character.y >= ch - character.h) { // if the character is under the bottom
character.y = ch - character.h;
character.jumping = false;
}
};