Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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 2071 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Devvie

Java games rock!

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


I have looked at this thread

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

This is what I do:
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


« 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


« 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.

Archive (165 views)
2017-02-27 19:41:49

numerical (508 views)
2017-02-21 07:32:16

numerical (510 views)
2017-02-21 07:31:46

theagentd (623 views)
2017-02-18 13:42:33

theagentd (618 views)
2017-02-18 13:35:16

h.pernpeintner (1790 views)
2017-01-24 22:39:11

h.pernpeintner (1731 views)
2017-01-24 22:38:32

Galdo (2299 views)
2017-01-12 13:44:09

Archive (2190 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2724 views)
2016-12-16 03:58:39
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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‑
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!