Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Threads, sleeping  (Read 1543 times)
0 Members and 1 Guest are viewing this topic.
Offline davey

Junior Newbie

Java games rock!

« Posted 2005-02-07 14:48:34 »

I'm not new to programming or Java in general, but very new to games programming.  I've not done it before and thought I'd have a go at writing something simple, so I started writing a breakout sort of game.

Developing on Linux I got a ball moving across the screen.  I created a thread which runs my moveBall() method whenever it's awake.

It's here that I have become unstuck.  To get any kind of reasonable speed on Linux I have to sleep for the lowest time available on my system (10ms).  (When I start doing any kind of collision detection in that method performance goes right off, but that's probably another problem).

However, when it runs on Windows, the sleep needs to be set to 1000 to move at a "reasonable" speed.

However, if sleeping for 1000 milliseconds is a second, it seems to me that the Windows one is wrong, even though it's more usable (i.e. I have a lot of scope to make it faster or slower).

So three questions, really.  Which OS sounds like it's exhibiting broken behaviour, and why is the performance so bad on Linux?

Is there any useful online introduction to the basics of games writing, especially in Java?  I'm not trying to make a living out of it, just get a bit of experience in something that could be fun.

Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #1 - Posted 2005-02-07 15:06:04 »

>if sleeping for 1000 milliseconds is a second, it seems to me
>that the Windows one is wrong

1000 msecs=1 second

But that works and it really sleeps for about a second - even on windows. So... most likely your code is to blame.

Well, in general that approach is flawed. Different machines have different speed. Each frame takes more or less time... so you actually need to determine how many time elapsed and adjust the wait time span accordingly.

If you're using 1.5, it's easy, because you can use nanoTime().

Like so:
private long timeNow, timeThen, timeLate = 0, timeDelta, desiredFrameRate=75;
private void sync(long frameFraction)
      long gapTo = frameFraction + timeThen;
            timeNow = System.nanoTime();
      }while(gapTo > timeNow+timeLate);

            timeLate = timeNow-gapTo;
            timeLate = 0;
      timeDelta = timeNow - timeThen;
      timeThen = timeNow;

You can ignore (remove) the timeDelta bit if you want to use tick based animation.

>I'm not trying to make a living out of it

There is no reason to point that out, because it doesn't make a difference Wink

>Is there any useful online introduction to the basics of
>games writing, especially in Java?

There are tons of information out there. and for example.

Check out kev's tuts:

弾幕 ☆ @mahonnaiseblog
Offline bauerr

Junior Devvie

Java!!!!!!!!!!! !!!

« Reply #2 - Posted 2005-02-07 16:39:09 »


you can also have a look at this tutorial:

But the tutorial  mentioned above is better.  Wink
This one is for real beginners.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davey

Junior Newbie

Java games rock!

« Reply #3 - Posted 2005-02-07 18:42:19 »


Ah.  Far better ways of doing things.  Time to junk my code and start again.

Thanks for the pointers
Pages: [1]
  ignore  |  Print  

Ecumene (113 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (241 views)
2017-08-02 12:19:43

cybrmynd (241 views)
2017-08-02 12:18:09

Sralse (256 views)
2017-07-25 17:13:48

Archive (874 views)
2017-04-27 17:45:51

buddyBro (1025 views)
2017-04-05 03:38:00

CopyableCougar4 (1578 views)
2017-03-24 15:39:42

theagentd (1376 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 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!