Java-Gaming.org
Java4K winners:
[
by our judges
|
by the community
]
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members
News
: Read the
Java Gaming Resources
, or peek at
the official Java tutorials
Home
Help
Search
Login
Register
Java-Gaming.org
>
Game Development
>
Game Play & Game Design
>
about Game Loop
Pages: [
1
]
Print
about Game Loop
(Read 1253 times)
0 Members and 2 Guests are viewing this topic.
winnerpig
JGO n00b
Posts: 3
about Game Loop
«
on:
2009-02-11 22:05:50
»
Generally,the game loop is built up manually,hower, in my opioin, the game application under awt or swing doesn't need to do this ,since we can override the defult method
Update()
with game logic (sprite move and collosion detect ,etc) and
Paint()
with code of graphic rendering ,and finally we just call
Repaint()
iteratively within a dead loop while(){} .
so, what's the
necessity of constructing a game loop
by ourself?
Hsaka
Jr. Member
Posts: 95
Medals: 2
Re: about Game Loop
«
Reply #1 on:
2009-02-11 23:00:18
»
Essentially, calling Repaint() adds a repaint request to the event queue and there is no notion of how long it remains in the queue before repaint is actually executed. Sometimes repaint requests may even be skipped or delayed.
Because Repaint() is at the mercy of the JVM, it is difficult to accurately control the timing of your game. In particular, we have no idea how long we should sleep for, which means we won't be able to maintain a consistent FPS.
Writing your own game loop is necessary because we don't know when repaint is actually completed. So, in order accurately control the timing of the game, we must take things into our own hands instead of overriding Update and Paint. The technique involves actively rendering our buffer image to the screen and implementing our own update method. This way we can measure the rendering time and accurately control how long to sleep.
winnerpig
JGO n00b
Posts: 3
Re: about Game Loop
«
Reply #2 on:
2009-02-17 03:03:16
»
Thanks a lot! There is another question: Is it the absolute way to create a thread handling the game loop seperately? other words, could I make the game loop without using thread programming?
Games published by our own members! Go get 'em!
CommanderKeith
JGO Wizard
Posts: 1455
Medals: 9
Re: about Game Loop
«
Reply #3 on:
2009-02-17 07:46:41
»
Hsaka's right, what he describes is sometimes called active rendering while your approach is passive rendering.
About threading, your code has to run in some thread, so you may as well make your own thread to do it in.
The trouble is, if you're using the AWT to listen for key and mouse events then you need to watch out since the keyPressed(KeyEvent e) etc methods run on the AWT event thread (also called the Event Dispatch Thread, EDT). So you often need to be careful not to modify game code from the EDT while it is running in your own game loop thread. I avoid this by storing the events recieved on the EDT, and then getting them in a synchronized way and processing them on the game loop thread.
StraightEdge 2D polygon project
SydneyEngine multiplayer top-down view shooter
Pages: [
1
]
Print
Jump to:
Please select a destination:
-----------------------------
Games Center
-----------------------------
=> Featured Games
=> Showcase
=> Contests
===> LWJGL16k - 2011
===> 4K Game Competition - 2012
===> JGO Comp Petite
===> Finished Contests
=====> 4K Game Competition - 2011
=====> 4K Game Competition - 2010
=====> 4K Game Competition - 2009
=====> 4K Game Competition - 2008
=====> 4K Game Competition - 2007
=====> 4K Game Competition - 2006
=====> 4K Game Competition - 2005
=====> Tiny Game 2010
=====> JGO Comp 2009
=====> 16K LWJGL Competition - 2005
=====> Java Technology Game Development Contest - 2004
-----------------------------
Discussions
-----------------------------
=> General Discussions
===> Suggestions
=> Business and Project Discussions
===> Jobs and Resumes
===> Community & Volunteer Projects
=> Miscellaneous Topics
-----------------------------
Game Development
-----------------------------
=> Newbie & Debugging Questions
=> Articles & tutorials
=> Game Play & Game Design
=> Game Mechanics
===> Artificial Intelligence
=> Networking & Multiplayer
=> Performance Tuning
=> Shared Code
-----------------------------
Java Game APIs & Engines
-----------------------------
=> Engines, Libraries and Tools
===> Java 3D
===> JInput
===> jMonkeyEngine
===> Xith3D Forums
===> Tools Discussion
=> Java 2D
===> JavaFX
=> OpenGL Development
===> JOGL Development
===> LWJGL Development
=> Java Sound & OpenAL
===> JOAL Development
=> Java on Mobile Devices
===> Android
===> J2ME
Loading...