0
我正在android Studio中使用libgdx製作遊戲。在這個遊戲中,得分與經過的時間相同(用(((System.currentTimeMillis() - startTime)/ 100)))。我還使用不同類的狀態(MenuState,PlayState和GameOverState)...在java中調用最後一次使用時間
public class PlayState extends State {
long startTime;
private SpriteBatch batch;
private BitmapFont font;
public PlayState(GameStateManager gsm) {
super(gsm);
cam.setToOrtho(false, Game.WIDTH, Game.HEIGHT);
startTime = System.currentTimeMillis();
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("text.fnt"), Gdx.files.internal("text.png"), false);
font.getData().setScale(.5f, .5f);
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
}
@Override
public void render(SpriteBatch sb) {
sb.setProjectionMatrix(cam.combined);
System.out.println("Score = " + ((System.currentTimeMillis() - startTime)/100));
batch.begin();
font.draw(batch, "Score: " + Float.toString((Float) ((System.currentTimeMillis() - startTime)/100f)), 20, 470);
font.setColor(Color.WHITE);
batch.end();
}
@Override
public void dispose() {
bg.dispose();
bird.dispose();
ground.dispose();
batch.dispose();
font.dispose();
for(Tube tube : tubes)
tube.dispose();
for(Cloud cloud : clouds)
cloud.dispose();
//stage.dispose();
System.out.println("Play State Disposed");
}
private void updateGround() {
if(cam.position.x - (cam.viewportWidth/2) > groundPos1.x + ground.getWidth())
groundPos1.add(ground.getWidth() * 2, 0);
if(cam.position.x - (cam.viewportWidth/2) > groundPos2.x + ground.getWidth())
groundPos2.add(ground.getWidth() * 2, 0);
}
}
我想要得到的最後得分GameOverState並打印在屏幕上... 有什麼辦法去做?