[java] Is this timing idea practical...?
I recently coded a quick and dirty pong game. My game loop was logic processing followed by a call to repaint() for the graphics stuff (of course, I''d overridden the protected paintComponent(Graphics g) method myself). To slow the loop down, I implemented a "sleep" timer class I''d heard about on the web.
I put my game loop in a run() method followed by a synchronized block that tells the game logic thread to wait for notification from the "sleep" timer thread. The timer wakes up 30 times every second (or however many times I want) and notifies the game logic thread.
This timer idea worked well for pong, but is it practical for other types of games?
This isn''''t life in the fast lane, it''''s life in the oncoming traffic.
-- Terry Pratchett
This doesn''t directly answer your question, but one thing you will run into is that in almost all game development situations, you are going to need to use active rendering rather than passive (calling repaint()). The tutorial at java.sun.com/books/tutorial touches on this in it''s fullscreen section, but if you search google or the forums at javagaming.org I''m sure you''ll turn up some pertinent information.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement