Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Problem with game loop  (Read 2468 times)
0 Members and 1 Guest are viewing this topic.
Offline Shazer2

Junior Member


Medals: 3


Aspiring developer.


« Posted 2012-10-10 07:51:40 »

I'm trying to replicate my code from in Python with Java to make a snake game. Upon setting up the basics of the game, a helpful person from IRC found me a thread which ra4king posted in that gave the exact details of a perfect game loop.

This is, however, where my problem started. I implemented all the code and then ran it. Immediately I noticed the window lagging and taking some time to move it around or actually do anything and the FPS that was being printed was 6000-8000, strange? This loop is here, http://www.java-gaming.org/topics/about-on-my-main-loop/26222/msg/229028/view.html#msg229028

My code is in the following - https://dl.dropbox.com/u/102063272/Snake.zip

Note: I am running this in Ubuntu, but when Xardov ran it on Windows 7 it runs perfectly fine at 800-1600 FPS.

"When you want to be successful as bad as you want to breathe, then you will be successful." - Eric Thomas
Offline aazimon
« Reply #1 - Posted 2012-10-10 16:53:05 »

My understanding is that the Java 2D is slower in Linux, with latest Java version (7) being fastest. What version of Java are you using?
Offline GabrielBailey74
« Reply #2 - Posted 2012-10-12 01:26:46 »

Don't bother implementing r4king's/rivens GameLoop lol, that's for a real time game, not for a 2D game loop, I also tried implementing it and it didn't work for shit lol.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StumpyStrust
« Reply #3 - Posted 2012-10-12 03:40:47 »

Gabriel why are you still here? It pains me to say this, but I have had similar issues using the busy loop idea where it would update too much. Best advice I can give for a very simple game is to just call Thread.sleep(1000/60). I have used that and not had any issues. Your game will go up or down 1-2 fps due to java's timing issue. If you want to keep game play consistent implement a veritable gameloop which is not too hard just do some googlfooing.

Offline gimbal

JGO Knight


Medals: 25



« Reply #4 - Posted 2012-10-12 20:44:09 »

Gabriel why are you still here? It pains me to say this, but I have had similar issues using the busy loop idea where it would update too much. Best advice I can give for a very simple game is to just call Thread.sleep(1000/60). I have used that and not had any issues. Your game will go up or down 1-2 fps due to java's timing issue. If you want to keep game play consistent implement a veritable gameloop which is not too hard just do some googlfooing.

Quick fix for the WINDOWS timing issue would be to simply start an endlessly sleeping daemon thread. If you're using LWJGL, update to the latest version which does it for you.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2012-10-12 20:49:38 »

Don't bother implementing r4king's/rivens GameLoop lol, that's for a real time game, not for a 2D game loop, I also tried implementing it and it didn't work for shit lol.
I don't see how 'realtime' excludes '2d'. A framerate throttler either works reliably or it doesn't.

My game-loop is behind LWJGL's Display.sync(...), so it probably is less shit than you make it out to be...

http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/opengl/Sync.java?revision=3803&view=markup

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Shazer2

Junior Member


Medals: 3


Aspiring developer.


« Reply #6 - Posted 2012-10-14 10:17:42 »

I'm just trying to implement some code so that I get constant slowed movement in a snake game. The way I imagine to achieve this would be to do:
1  
2  
3  
4  
5  
6  
7  
8  
long initialTime = System.currentTimeMillis();
while (running) {
    if (System.currentTimeMillis() - initialTime >= 1000) {
        render();
        update();
        initialTime = System.currentTimeMillis();
    }
}


However I still get the super laggy window problem.

"When you want to be successful as bad as you want to breathe, then you will be successful." - Eric Thomas
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!