我是Java编程和Android Studio的新手,我尝试使用我的初学者Java知识来构建Flappy Bird游戏。但是问题是机翼的速度非常快,当我点击屏幕时,电子管的显示速度也很快。如何解决这个问题?我用HTC手机检查了这款游戏。我没有使用模拟器来检查游戏。
SpriteBatch batch;
Texture background;
Texture[] birds;
int flapstate = 0;
float birdY = 0;
float velocity = 0;
int gameState = 0;
float gravity = 2;
Texture toptube;
Texture bottomtube;
float gap = 400;
float maxTubeOffset;
Random randomGenarator;
float tubeOffset;
batch = new SpriteBatch();
background = new Texture("bg.png");
toptube = new Texture("toptube.png");
bottomtube = new Texture("bottomtube.png");
maxTubeOffset = Gdx.graphics.getHeight() / 2 - gap / 2 - 100;
randomGenarator = new Random();
birds = new Texture[2];
birds[0] = new Texture("bird.png");
birds[1] = new Texture("bird2.png");
birdY = Gdx.graphics.getHeight() / 2 - birds[0].getHeight() / 2;
batch.begin();
batch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
if (gameState != 0) {
if (Gdx.input.justTouched()) {
velocity = -30;
tubeOffset = (randomGenarator.nextFloat() - 0.5f) * (Gdx.graphics.getHeight() - gap - 200);
batch.draw(toptube, Gdx.graphics.getWidth() / 2 - toptube.getWidth() / 2, Gdx.graphics.getHeight() / 2 + gap / 2 + tubeOffset);
batch.draw(bottomtube, Gdx.graphics.getWidth() / 2 - bottomtube.getWidth() / 2, Gdx.graphics.getHeight() / 2 - gap / 2 - bottomtube.getHeight() + tubeOffset);
}
if (birdY > 0 || velocity < 0){
velocity = velocity + gravity;
birdY -= velocity;
}
}
else {
if (Gdx.input.justTouched()) {
gameState = 1;
}
}
if (flapstate == 0) {
flapstate = 1;
} else {
{
flapstate = 0;
}
}
batch.draw(birds[flapstate], Gdx.graphics.getWidth() / 2 - birds[flapstate].getWidth() / 2, birdY);
batch.end();
}