0
我在遊戲中添加了一些東西,這樣當你按下空間時,你會得到一個小的速度提升。但是,只有在使用WASD密鑰時才能正常工作。如果按上下左右方向鍵,增強功能將不起作用,否則會起作用。任何人都可以解釋它爲什麼這樣做?有人可以解釋這一點嗎? (運動不能正常工作)
下面的代碼:
boostTimer += Gdx.graphics.getDeltaTime();
if(boostTimer > 3){
snailBoost = 0;
boostTimer = 0;
}
//movement
if(Gdx.input.isKeyPressed(Keys.LEFT) || Gdx.input.isKeyPressed(Keys.A)){
if(Gdx.input.isKeyPressed(Keys.SPACE) && snailBoost < 20){
snailBoost++;
snail.getBounds().x -= (snailSpeed + 100) * delta;
}
//flips the sprite
snail.getSprite().setFlip(false, true);
snail.getBounds().x -= snailSpeed * delta;
//handles what happens when you go outside the game world
if(snail.getBounds().x < -100)snail.getBounds().x = 1920;
}
if(Gdx.input.isKeyPressed(Keys.RIGHT) || Gdx.input.isKeyPressed(Keys.D)){
if(Gdx.input.isKeyPressed(Keys.SPACE) && snailBoost < 20){
snailBoost++;
snail.getBounds().x += (snailSpeed + 100) * delta;
}
snail.getSprite().setFlip(true, true);
snail.getBounds().x += snailSpeed * delta;
if(snail.getBounds().x > 2020)snail.getBounds().x = -100;
}
if(Gdx.input.isKeyPressed(Keys.UP) || Gdx.input.isKeyPressed(Keys.W)){
if(Gdx.input.isKeyPressed(Keys.SPACE) && snailBoost < 20){
snailBoost++;
snail.getBounds().y -= (snailSpeed + 100) * delta;
}
snail.getBounds().y -= snailSpeed * delta;
if(snail.getBounds().y < -100)snail.getBounds().y = 1080;
}
if(Gdx.input.isKeyPressed(Keys.DOWN) || Gdx.input.isKeyPressed(Keys.S)){
if(Gdx.input.isKeyPressed(Keys.SPACE) && snailBoost < 20){
snailBoost++;
snail.getBounds().y += (snailSpeed + 100) * delta;
}
snail.getBounds().y += snailSpeed * delta;
if(snail.getBounds().y > 1080)snail.getBounds().y = -100;
}
對不起亂碼。 :P 還是遊戲開發的新手。
好的,謝謝你的回答。 –