views:

29

answers:

1

Hi, I made a little Shooter game with two ships firing at each other. I used methods of paintComponent for drawing or moving object, but for some reason it ran at a different speed on each computer.

I searched for a solution and made some modifications to my game like drawing and moving objects in thread. Now it runs at the same speed on every сomputer. Also if I change size. But the problem is I used J3DTimer.getValue().

To use this library I downloaded Java3d. If the computer does not have this library or installation my game does not work. How can I solve this problem? Should I tell everyone to setup Java##? :))

Also I tried using standard System.currentTimeMillis(), but then my game works very slow... Any ideas?

+2  A: 

Since Java 1.5 there has been a method called System.nanoTime(), which is generally much more precise than System.currentTimeMillis() (depending on the capabilities of the underlying hardware).

I think System.nanoTime() should be a drop-in replacement for J3DTimer.getValue(). That way you remove your dependency on the Java3D library.

Ash
I used instead of J3D timer but with same configuration of my Thread sleep J3D was working smoothly but now on screen my strings have some flicking.Am I not getting the same value from J3DTimer.getValue() and System.nanoTime() ??if there is some differences what is it? I can modify Thread.sleep method with this value
Meko
I just downloaded the Java3D source code from https://java3d.dev.java.net and looked at `J3DTimer.getValue()`. The method is basically a wrapper for `System.nanoTime()` anyway (at least in version 1.5.2 of Java3D). I'm not sure how changing between the two could alter the way your application behaves.
Ash