Java3D and Threads

Hello all,

I’m working on a 3D Drag Racing game using a mixture of a 3D canvas and a JPanel.

The game is a simple racing game where the user’s car accelerates through 6 gears, with each gear shift giving an increase in speed. When the tachometer hits the red (time to shift gears) The user must play a quick reflex mini game. If the user passes, the gear shifts and accelerates the car. The car will not accelerate until the mini game has been completed.

The Jpanel displays the Tachometer which is animated using threads. The mini games such as a meter with a quick moving bar that must be timed to hit the center, is also animated using threads. All of the mini games use Java2D graphics.

Threads also control the movement of the car in the 3D canvas and each thread cycle for the car speed sleeps for 20 and its pretty smooth.

I’m using threads rather that behaviors for the movement of the car, because if i tried to use a wakeuponelapsedframes behavior the threads controlling the mini games were very inconsistent, and seemed like each time a mini game ran, or tachometer moved, it would lag up and play catch up with the movement of the car in a very jerky manner.

My main problem now consists of jerky movements of the car if the thread sleep time is set too high. If the car speed thread sleep time is too low, then the whole thing lags up. If the sleep time is too high then the mini games run at good speed and in Sync with the movement, however the movement is very jerky and the car kind of flickers around back and forth.

Does anyone know why a problem like this would occur? Too many threads running at once? If so, what is the best way of doing what I am trying to accomplish?

I thought about making a 3d tachometer and mini games, but i’d rather not since all the code for the mini games has already been written by my partner :slight_smile:

Plus, i’m not sure if making a 3d tachometer would even improve performance. I’d have to use seperate behaviors to animate the mini games and tachometer.

I’m also having a problem with the 2d graphics being displayed quickly enough when the sleep time is too low. For instance, when the tachometer hits gear 2 and its time for the first minigame to come up… then the game will not come up right when it is supposed to and there is some wait time.

Any suggestions?

Thanks