Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Simple java timer question

$
0
0
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.

		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.

Viewing all articles
Browse latest Browse all 51036

Trending Articles