Timer
I'm developing a new game and am having a small issue. I need to create some sort of timer. But I do not need an advanced one, that will throw an action event. Just a simple operation like... call timer, wait till timer returns, then continue. I don't want to use Thread.sleep() because I don't want to stop all operations going on. What do I do? Thanks.
sleep only affects the currently executing Thread, so it does essencially behave as you want.[quote]call timer, wait till timer returns[/quote]
Abusea at 2007-7-15 14:27:10 >

Well, the problem i'm having with it, is that when i use Thread.sleep() it stops any windowing things that are done. The set up works like this. I've got my window, and inside the main class that drives the game logic, i do a series of movements. Repaint() is constantly being called. In between each movement I need to have a pause... when I use Thread.sleep() it seems to lock up the whole GUI so that no repainting occurs or anything else. So it seems to effect the entire program, which is why I don't want to use it.
ah, that would be because you are doing your repainting in the event scheduler Thread.My suggestion, stop using passive rendering; use active rendering.
Abusea at 2007-7-15 14:27:10 >

Its a native dll wrapper for the high resolution timer on Windows.Dunno which timer.dll you have seen, but i'd guess its the 1 included in the GAGE library written by jbanes ( http://forum.java.sun.com/profile.jsp?user=27070)
Abusea at 2007-7-15 14:27:10 >

Alright, so i've set up a Timer/TimerTask scenario now. I created a TimerTask class, which takes in the main thread as a parameter, then calls a the needed method when executed. In the main thread, I create a Timer based on this TimerTask, passing in the main class object into it as the parameter. It appears to work perfectly fine, however, repaint still does not work. I wrote a custom method called render() that looks basically like this...
public void render()
{
Graphics g = mainProgram.getGraphics();
paintComponents(g);
g.dispose();
}
Again, using this method instead of repaint() doesn't work. When all the timers are done and the process is "complete", the window stays the same. If I minimize it, then restore the window... it repaints the changes that were made.
I'm really not understanding why it isn't updating regularly. There's gotta be a simple way to fix/handle this problem.