i have a countdown timer from 10 to 0 when click outside the box the time should just stop or when it hits zero it should stop at 0. but if it stops it flickers between like 4.51 and 4.52 (random stopping numbers) instead of one or the other. and at zero when the games over it flickers at 0.01 and 0.03. how do i make it a solid number in each case. here is my show and render methods
@Override
public void show() {
font2 = new BitmapFont(Gdx.files.internal("text.fnt"), true);
font2.setScale(.25f, -.25f);
score = 0;
c = new Color(Color.WHITE);
style = new LabelStyle(font2,c);
label = new CustomLabel("" , style);
label.setPosition(0,900);
seconds = new CustomLabel("" , style);
seconds.setPosition(200,900);
stage = new Stage();
Gdx.input.setInputProcessor(stage);
boxImage = new Texture(Gdx.files.internal("box.png"));
pop = new Image(boxImage);
pop.setPosition(220,220);
stage.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
int num1= (int)MathUtils.random(50, 500);
int num2= (int)MathUtils.random(50, 500);
//check if box is hit
if (pop.equals(stage.hit(x, y, false))) {
// System.out.println("num1:"+num1+" num2:"+num2);
//System.out.println("score :"+score);
pop.setPosition(num1,num2);
score++;
}
else {
currentState = GameState.GAMEOVER;
}
}
});
stage.addActor(label);
stage.addActor(seconds);
stage.addActor(pop);
}
@Override
public void render(float delta) {
label.updateText("SCORE: "+toString(score));
if( time<=0){
time = 0;
seconds.updateText(String.format("time: %,.2f", time));
}
seconds.updateText(String.format("time: %,.2f", time));
switch (currentState)
{
case RUNNING:
{
time-= delta;
if(time<=0)
{
setGameState(GameState.GAMEOVER);
}
Gdx.gl.glClearColor(0, 0 , 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
break;
}
case PAUSED:
{
System.out.println("pauseddd");
///make pause screen
break;
}
case GAMEOVER:
{
time=0;
System.out.println("gameover");
break;
}
default:
break;
}
}
0 comments:
Post a Comment