Hello,
Im in the middle of a larger school project, where we are making the classic game Space Invaders!
My question if revolving around timers, since my goal is to call a method every so and so seconds (10 sec or so).
The thing is when i run the program, the timer work fine until first tick, and then just executes the task every run-though, with no delay.
The game.addHighscore is simply something i use to test the time intervals.
This is placed in my game update function. I've tried to make the timer handle a class variable with no succes.
(I cant post entire code, since its very long and 99,99% irrelevant
)
Hope you guys can help me.
Im in the middle of a larger school project, where we are making the classic game Space Invaders!
My question if revolving around timers, since my goal is to call a method every so and so seconds (10 sec or so).
The thing is when i run the program, the timer work fine until first tick, and then just executes the task every run-though, with no delay.
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
game.addHighscore(10);
timer.cancel();
}
},1000);
The game.addHighscore is simply something i use to test the time intervals.
This is placed in my game update function. I've tried to make the timer handle a class variable with no succes.
(I cant post entire code, since its very long and 99,99% irrelevant
Hope you guys can help me.