Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 1504 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Duke




Java games rock!


« Posted 2006-03-18 12: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 14: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 Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2006-04-04 10: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!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #3 - Posted 2006-04-04 14: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.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (53 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!