DarkVania

I actually just made a few changes to the game, and realized i probably should have posted this in the WIP sub-forum but I didn’t see it… can a mod delete this Thread so that i can put it there and not get bashed as some sort of spammer please?

Anyways, for the time being i’ll include the changes here…

Should I upload a new version and add it here or wait for this to be deleted?

NOTE: One major issue that i have with the game is that on some machines, the player will jump lower than on others, i think this is because my game loop sleeps for a period of time (set to 9ms i believe) but even though it’s supposed to sleep the same across all machines I realize relying on System.millis in not a good approach, but i don’t see how i can have the game sleep the same amount of actual real time across all machines, any ideas?

I don’t know how it works in Java 2D, but Slick2D has a parameter ‘delta’ that’s a frame-rate dependent offset. To have a 9ms pause, you would do (delta*9) or something similar. This keeps the time constant irrespective of the performance (read framerate)

There’s System.nanoTime as in here:


/**
 * Get the time in milliseconds
 * 
 * Return the system time in milliseconds by dividing by 1 million
 */
public long getTime() {
    return System.nanoTime() / 1000000;
}

;D

I keep hearing of this Slick2D thing on this forum… does that have faster drawing functions than Java2D or something? would it be a good idea for me to port this over to that?

anyways, about the nanoTime, it seems to me that if the computer clock is fucked up and giving me some weird millisecond time, i assume it would also give me fucked up nanosecond time, but i’ll try your method and write back the results!

There is another known hack to force Windows to use an high precision timer, I use it in my game:

Doing gameloops is easy but hard to get just right.
Slick2D and Libgdx are frameworks that use OpenGL, so they are inherently faster and more stable - they also do things like gameloop on their own.
Slick2D is kinda dying - however porting from Java2D to Slick2D is very straight forward since almost everything has the same or similar names / functions (Slick2D is still very effective and usable for games of this size)
When you want to include sound and or music, you will have to get an external library anyway, since JavaSound is the biggest pile of shit ever; and Slick2D already has sound playback and stuff

hmmm I’m getting there, i just asked my teacher about sleeping inside a game loop and he said that should never be done, the game should run as fast as it can but use some sort of variable that dictates how “fast” a sprite should move for that particular frame.

So i did just that, i no longer have a Thread.sleep(9) on my gameLoop, which is really, really good, it improves the look and fluidity on my laptop like you wouldn’t believe… thx guys, this is a really helpful forum, i just wish it were a bit more alive!