Multiple Timers?
For a real-time strategy game, when you construct a building or unit, it's supposed to take a certain amount of time to build.
If Unit A takes 3 seconds to build, how do I ensure that it takes 3 seconds on any computer no matter it's graphical power.
See, if I have:
timerActionPerformed(){
drawGUI()
drawUnits()
tickConstruction()// this is where some time is taken off Unit A's production time
}
If there are lots of graphics to display, a bad computer might take 5 seconds for the unit to be built.
So I thought maybe this would work as a solution:
timerActionPerformed(){//Timer A
drawGUI()
drawUnits()
}
timerActionPerformed(){//Timer B
tickConstruction()
}
Would this work, or would the lag from Timer A's drawing slow down Timer B?
Thanks
[1116 byte] By [
Nethera] at [2007-11-26 19:44:28]

# 1
In the action handler only do the tickConstruction() call. Only perform the drawing of items in the paint method. Separate the data from the drawing. You don't need to do drawing commands any time you update the structure of a game object (either building, damaging or removing them). You do need to update the drawing xx times per second (done in the paint method of your drawing surface's buffer before it is displayed).
Things to look up (if you don't already know about them):
double buffering
game programming
Good luck with your game. :)
# 5
You'd be surprised what you can do in that time. The newer JREs handle collections and graphics better than before.
http://sourceforge.net/projects/javoids/
The jar you can download has all of the code in it. Take a look at what I did. If you don't have thousands of objects to redraw or keep track of it can run quite well on older PCs (preferably with newer JREs).
On the PC I'm using here it runs fine. I'll have to check it on my slower PC (Athlon XP 2000+).
I tried your atom game it was pretty nerve wracking at first.
# 7
If I remember correctly I used the layout from Winroids for the keyboard. They are configurable so if you don't like them you can change them.
Personally I can't stand the space button being used to fire a weapon since I'm right handed I can press the button a lot faster with it. By using the arrows for the shield, fire, thrust and afterburner I was able to concentrate the keys together without having to worry if numlock was on/off.
Anyway, I think there are some threads that talk about timing in games that basically say get the time, do your non drawing stuff and when finished check to see if it exceeds the start time plus some delta, if not wait a tiny bit more, otherwise draw the results. I don't think there is any way to guarantee response times on every platform, only a best effort to complete it in so much time. If it exceed those desired times may suggest a minimum hardware requirement (CPU/GRAPHICS) that is not being met and should be upgraded for your game.