我遇到的问题是我不知道如何让角色停止跳跃。
例如,当我不断地击中空间时,它会不停地跳跃。当我按下空格键时,我希望它跳跃,而当 MC 跳跃时,我想禁用空格键(或者如果可能的话,你也可以告诉我如何禁用MouseEvents
),以便在空中时 MC 只能跳跃一次。
var gravity = 0.8;
var floor = 251;
player.y = floor;
player.speedY = 0;
player.impulsion = 10;
stage.addEventListener(Event.ENTER_FRAME, enterframe);
function enterframe(e:Event) {
player.speedY += gravity;
player.y += player.speedY;
if(player.y > floor) {
player.speedY = 0;
player.y = floor
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, space);
function space(e:KeyboardEvent) {
if(e.keyCode == Keyboard.SPACE) {
player.speedY = -player.impulsion
}
}