我正在建造一台2D平台游戏机,现在正在试图让我的玩家在按住空格键时跳得更长。现在玩家可以上下跳动,但是当你按住键时,机器人独角兽会出现类似于这种效果的id。我会如何去做这件事?我没有使用相位器或任何东西,而且大多数教程都是使用它。下面有什么,我有我的更新方法:在JavaScript中延长跳跃精灵?
var gameEngine = this.game;
if (gameEngine.keyMap["Space"] && !this.jumping) { //only jump if not already in mid jump
this.jumping = true;
this.animationCurrent.elapsedTime = 0;
this.game.space = false;
}
if (this.jumping) {
if (this.animationCurrent.isDone()) {
this.animationCurrent.elapsedTime = 0;
this.jumping = false;
}
var jumpDistance = this.animationCurrent.elapsedTime/
this.animationCurrent.totalTime;
var totalHeight = 150;
if (jumpDistance > 0.5)
jumpDistance = 1 - jumpDistance;
var height = totalHeight * (-4 * (jumpDistance * jumpDistance - jumpDistance));
this.y = this.ground - height;
console.log(this.y);
}
你使用onkeypressed?如果是这样,这可能是不可能的设计。你在使用onkeydown吗?如果是这样,这将允许您随着时间节省跳跃高度作为奖励。例如,+150,+ 15,+ 5,+ 1。 –
@TravisJ我使用onkeydown – thatsnifty