Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  time based movement ,unstable delta calculation from sys.gettime  (Read 1254 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Member




Java games rock!


« Posted 2006-03-18 13:47:13 »

Hi

I have looked at this thread http://www.java-gaming.org/forums/index.php?topic=11443.0

Thats where I found the SystemTimer class, and how to use it.

This is what I do:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
long delta = SystemTimer.getTime() - lastLoopTime;
lastLoopTime = SystemTimer.getTime();

System.out.println("delta: "+delta);

float oldy = gameview.getYOnMap();
float speed = 30.0f;
float bxmov = (speed * delta) / 1000; //pixels to move

System.out.println("bxmov: "+bxmov);
System.out.println("moving it: "+(int)bxmov);

gameview.setYOnMap((gameview.getYOnMap() - bxmov)); //set the new location


When I look at the console and the different delta's it jumps alot up and down, everything from 18ms to 30ms and
this makes the movement look like many small movements then suddenly a big one..

If I just set it to move 1pixel each time without any movement timing its soo silky smooth. But since its 60fps even only 1 pixel pr frame is too fast..So
I need to time it to get slower movements.

Here's the delta output from console:

timerTicksPerSecond: 1000
delta: 53575561
delta: 64
delta: 32
delta: 32
delta: 32
delta: 33
delta: 32
delta: 32
delta: 17
delta: 18
delta: 18
delta: 17
delta: 18
delta: 17
delta: 18
delta: 17
delta: 33
delta: 32
delta: 32
delta: 32
delta: 33
delta: 32
delta: 32
delta: 32
delta: 19
delta: 17
delta: 18
delta: 18
delta: 17
delta: 18
delta: 17

I tried to set the speed to 60, so that should be 1pixel pr frame but it still jumps up and down its not even close to how smooth it is
when I use only a static +1 movement each tick.

Anyone got any tips?
Offline Vage

Senior Newbie




learning++;


« Reply #1 - Posted 2006-03-20 15:51:20 »

I'm not sure what the underlying code is behind SystemTimer, but you might try System.nanoTime() from Java 5.0, if only for comparision purposes.

Personally, you could strap me into a mech cockpit with 47 virtual HUD displays, two complex hand controls and foot pedals and I'd be grinning like the gamer freak I am.
Offline erikd

JGO Knight


Medals: 3
Projects: 3


Maximumisness


« Reply #2 - Posted 2006-04-04 12:08:00 »

IIRC, you have to call Sys.getTimerResolution() regularly as it recalibrates the timer. I'm not sure if this is still the case with the new 1ms timer though, or if it's the cause of your problem at all.

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #3 - Posted 2006-04-04 16:24:00 »

I dont know that SystemTimer class, but its usual for deltas to jump around a bit. A common way to deal with it is applying some light damping (like rolling-average the last 3 or 5 values).

The thing which most likely amplified the jumpyness was printing the values to System.out. Writing stuff there is a surprisingly heavy operation. Try writing it to a file or try using some time graph.

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (105 views)
2013-05-17 21:29:12

alaslipknot (114 views)
2013-05-16 21:24:48

gouessej (142 views)
2013-05-16 00:53:38

gouessej (138 views)
2013-05-16 00:17:58

theagentd (150 views)
2013-05-15 15:01:13

theagentd (135 views)
2013-05-15 15:00:54

StreetDoggy (178 views)
2013-05-14 15:56:26

kutucuk (201 views)
2013-05-12 17:10:36

kutucuk (202 views)
2013-05-12 15:36:09

UnluckyDevil (208 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.127 seconds with 20 queries.