Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  Print  
  Player sprite just doesnt move smooth?  (Read 8068 times)
0 Members and 1 Guest are viewing this topic.
Offline Addictman

Full Member
**

Posts: 204
Medals: 5


Java games rock!


« Reply #30 on: 2011-05-06 12:59:02 »

My point was that my rendering loop is nothing special whatsoever, except that it uses Thread.yield() instead of Thread.sleep()
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 8089
Medals: 96


Eh? Who? What? ... Me?


« Reply #31 on: 2011-05-06 15:43:52 »

I use yield() these days still. sleep() just too unreliable.

Cas Smiley

Offline Cero

JGO Neuromancer
****

Posts: 1050
Medals: 18



« Reply #32 on: 2011-06-04 06:35:06 »

I never ever used .sleep(), always .yield()

and its just not a code issue: this behavior only occurs on the DirectX pipeline. Using the OpenGL pipeline forces even a windowed game to VSync when using bufferedstrategy.
in that case, when using opengl, I obviously don't even need my game slow down class; since its automatically vsynced.

no screentearing ever on opengl. obviously that pipeline has so many problems...

this is my experience with java2D + pipelines... my engine is switching to lwjgl soon; I hope it will be gone alltogether.

here is how I do the slow down: (btw Awt.Toolkit.sync() results in abysmal slowdowns)

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  
public class FrameSkipper
{
    private int fps;
    private long timeThen;

    public FrameSkipper(int frameRate)
    {
        fps = frameRate;
        timeThen = System.nanoTime();
    }

    public void changeFPS(int frameRate)
    {
        fps = frameRate;
    }

    public void sync()
    {
        long gapTo = 1000000000L / fps + timeThen;
        long timeNow = System.nanoTime();

        while (gapTo > timeNow)
        {
            Thread.yield();
            timeNow = System.nanoTime();
        }

        timeThen = timeNow;
    }
}


so you initialize with the FPS you want, and then just call sync every frame.

also note: I currently do not use any threads; I would like to maintain a frame based synced game, which should be entirely possible (like your standard C++ game)

Games published by our own members! Go get 'em!
Offline Swattkidd7

Full Member
**

Posts: 203



« Reply #33 on: 2011-08-04 07:36:20 »

If ten more persons come and claim they can animate a moving circle/rectangle without stuttering... I think I have to believe it. Why it is so complicated just to prove it and give a minimal example so that we all can learn from the rendering loop?
Doesn't seem to be that simple...

I would love to see this also.

old thread but still a problem.
Offline Rejechted

Full Member
**

Posts: 119
Medals: 1


Just a guy making some indie games :D


« Reply #34 on: 2011-09-22 09:39:45 »

I see a similar problem in our OpenGL Application in windowed mode but we think it's because we aren't using linear interpolation when we render, so every second or so (pretty predictable, depends on updates/second), we get a slight stutter where everything seems to "shift" and "snap back" while moving the character from side to side. 

Trying really hard to discern whether this is due to some vertical sync issue, loop timing, or lack of interpolation.

We use Phys2D with a fixed timestep.

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Offline sproingie

JGO Strike Force
***

Posts: 899
Medals: 55



« Reply #35 on: 2011-09-22 12:45:16 »

On Windows, the compositor will drop frames since it doesn't seem to sync up with OpenGL the way it does with DirectX.  Just a simple bouncing box will occasionally make a jump due to a dropped frame.  It's still the same actual speed, but the discontinuity is very visible.   I don't know any way around this annoying behavior other than disabling aero or running fullscreen.

Offline Rejechted

Full Member
**

Posts: 119
Medals: 1


Just a guy making some indie games :D


« Reply #36 on: 2011-09-22 22:20:43 »

We now enable vsync and run in full screen which produces the optimal results with our fixed timestep - no screen tearing, and no stuttering, looks like a knife through butter.

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Offline Z-Man

Sr. Member
**

Posts: 270
Medals: 7



« Reply #37 on: 2011-09-22 22:22:46 »

We now enable vsync and run in full screen which produces the optimal results with our fixed timestep - no screen tearing, and no stuttering, looks like a knife through butter.
When I use LWJGL (which uses OpenGL) I just turn on VSync and interpolate the movement of the sprite. Works great.

"Anything that can possibly go wrong, does."
Pages: 1 [2]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.131 seconds with 20 queries.