Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  Need help with flickering and timestep problem in my game  (Read 538 times)
0 Members and 1 Guest are viewing this topic.
Offline Cesar_Biker

Junior Newbie





« Posted 2013-05-15 17:55:28 »

Hello, I'm new user in this forum but I was reading a lot of threads that helped me but in this case I didn't get the answer.

My problem is that my game is flickering all the objects (jumping backforward) and I don't understand why.
I tried to use delta for the movement..., I tried to use sleep..., but nothing works. I don't know what more to do, and in other tests with delta and "unlimited fps" the code works perfect.
Example of code that works:
http://pastebin.com/vjZ0cgdh

This is my game loop:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
private static void bucleJoc()
   {
      double passat = 0;
      double dividir_entre = 1000.0/60.0;//cada milisegon
      ultimTemps = lastFrame = Sys.getTime();

      objectes = new ArrayList<ObjecteJoc>();
      jugador = new Jugador(0, ALTURA / 2 - Jugador.ALTURA / 2);
      enemic = new Enemic(AMPLADA - Enemic.AMPLADA, ALTURA / 2 - Jugador.ALTURA / 2);
      pilota = new Pilota(AMPLADA / 2 - Pilota.MIDA / 2, ALTURA / 2 - Pilota.MIDA / 2);
      objectes.add(jugador);
      objectes.add(enemic);
      objectes.add(pilota);
      getDelta();

      while(!Display.isCloseRequested())
      {
         double delta = getDelta();
         passat += delta;

         while(passat >= dividir_entre)
         {
            glClear(GL_COLOR_BUFFER_BIT);
            glLoadIdentity();

            obtindreTecles();
            actualitzar(passat);
            passat = 0;
         }
         renderitzar();
         
         try
         {
            Thread.sleep(2);  
         } catch(InterruptedException e)
         {
            e.printStackTrace();
         }

         actualitzaFPS();
         Display.update();
      }
      tancarTot();
   }


This is my render function:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
public void renderitzar()
   {
      crearRectangle(x,y,amplada,altura,cVermell,cVerd,cBlau,rotacio);
   }

   private void crearRectangle(float x, float y, int amplada, int altura, int vermell, int verd, int blau, float rotacio)
   {
      glPushMatrix();
      {
         glColor3ub((byte) vermell, (byte) verd, (byte) blau);

         glTranslatef(x,y,0);

         /*glTranslatef(amplada/2,altura/2,0);
         glRotatef(rotacio,0,0,1);
         glTranslatef(-amplada/2,-altura/2,0);*/


         glBegin(GL_QUADS);
            glVertex2f(0,0);
            glVertex2f(amplada,0);
            glVertex2f(amplada,altura);
            glVertex2f(0,altura);
         glEnd();
      }
      glPopMatrix();
   }


And this my update for the movement:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public void actualitzar(double delta)
   {
      System.out.println("Y: "+ this.y);
     
      if(Keyboard.isKeyDown(Keyboard.KEY_W) || Keyboard.isKeyDown(Keyboard.KEY_UP))
      {
         this.y += VEL * delta;
      }
      if(Keyboard.isKeyDown(Keyboard.KEY_S) || Keyboard.isKeyDown(Keyboard.KEY_DOWN))
      {
         this.y -= VEL * delta;
      }
      //System.out.println(this.y + " " + delta);
     
     
      if(this.y >= Joc.ALTURA - ALTURA / 2)
         this.y = Joc.ALTURA - ALTURA / 2;

      if(this.y <= 0 - ALTURA / 2)
         this.y = -ALTURA / 2;
   }


If you want I can post the full code.
Thanks for the help and attention.
Offline Cero
« Reply #1 - Posted 2013-05-15 18:12:48 »

You using delta timing.
Getting it right is quite hard. So this is expected when you use delta.

Either learn really about gameloops and delta timesteps, or dont use delta - it depends on what you target

Offline alaslipknot
« Reply #2 - Posted 2013-05-15 18:54:21 »

You using delta timing.
Getting it right is quite hard. So this is expected when you use delta.

Either learn really about gameloops and delta timesteps, or dont use delta - it depends on what you target

am kinda having the same problem, my game looks a little bit flickering even in 60FPS and am using Delta (same code i found in the LWJGL wiki ) so i want to ask you, what do you mean by it depends on what you target ? and is it possible to use a different game loop ?

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cesar_Biker

Junior Newbie





« Reply #3 - Posted 2013-05-15 20:03:08 »

You using delta timing.
Getting it right is quite hard. So this is expected when you use delta.

Either learn really about gameloops and delta timesteps, or dont use delta - it depends on what you target
Yes I know, I spend a lot of time trying to understand how delta works because all the good tutorials are in english and I'm spanish so it's a bit difficult. But I want my game to work with it, and all the others I can make in the future, because it's FPS independent, so it can run in almost any computer. But anyways, thanks for your answer.
Offline Cero
« Reply #4 - Posted 2013-05-16 08:30:29 »

You using delta timing.
Getting it right is quite hard. So this is expected when you use delta.

Either learn really about gameloops and delta timesteps, or dont use delta - it depends on what you target

am kinda having the same problem, my game looks a little bit flickering even in 60FPS and am using Delta (same code i found in the LWJGL wiki ) so i want to ask you, what do you mean by it depends on what you target ? and is it possible to use a different game loop ?

Yes absolutely. You can just do your game frame-based.
Time/Delta vs Frame based game loops are, at least in the indie area a holy war...
The frame based approach is simply: Make sure your game runs a rock solid framerate, eg 60fps and dont use delta. Or have too modes 30 and 60.
Many many games are like this, since you dont have to use delta if you are sure that your framerate is constant, which is a good thing anyway.

However it kinda depends what platform you target and what your game is like.
If you are using a platform like say a console, you can easily use frame-based, since it will run the same anywhere.
And it also depends on what is going on in your game... If there are really busy sections and really idle sections you may have to use some delta.

Of our 4 games, 3 use frame-based and one uses some delta by applying a low pass filter over the delta values and stuff... Its really hard to get it right.
But if your game has like a minimum system requirement and you cap the fps,  the game will only run slower on hardware that is simply too slow anyway.

So yeah I'm kinda frame-based.

To me, the problems you encounter with using delta far exceed the benefits in most cases.

Offline relminator
« Reply #5 - Posted 2013-05-16 14:34:30 »

Why not use both? You could run your logic framebased while only updating at 60 fps.

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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!