I have a big problem with frame rate. When I draw only 1 sprite and try to move it when FPS is below 400 without VSync I have lags. It isn't smooth movement. When I use VSync it works almost good, but every second instead 60 fps, frame rate jump to ~2000 for 1 frame. When this happen movement stutters. Also without this frame rate jumps, movement stutters, but less than without VSync. When FPS > 500 everything is fine. This isn't due to bad hardware. Can I do something with it?
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
img.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
font = new BitmapFont();
player = new Sprite(img);
x = 100;
y=100;
player.setPosition(x, y);
//camera = new OrthographicCamera(640, 480);
//multiGame = new MultiGame();
//multiGame.create();
//camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0);
//camera.update();
}
@Override
public void render ()
{
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
update();
batch.begin();
font.draw(batch, "" + (int)(1/time), 600, 450);
player.draw(batch);
batch.end();
}
private void update()
{
time = Gdx.graphics.getDeltaTime();
if(Gdx.input.isKeyPressed(Keys.D))
{
x+=100 * time;
}
if(Gdx.input.isKeyPressed(Keys.D))
{
x-=60 * time;
}
player.setPosition(x, y);
}
}
Only generated code with some lines of keys handling and sprite drawing. Every second FPS grow up to 2000 for 1 frame... and sprite is stuttering.
It's desktop launcher:
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.vSyncEnabled = true;
config.foregroundFPS=60;
config.backgroundFPS=60;
new LwjglApplication(new IndustrialServer(), config);}
EDIT: I discovered that when it's in window mode... it stuttered... many times in 1 second... but when it's in fullscreen mode only every second... (it's connected with fps jumping because when application work in window mode... it stuttered without jump FPS... :/ )
And i rejestred this fps when app worked for 30 seconds (FPS < 40 or > 70): 742, 104, 19, 1749, 39, 132, 76, 76, 77, 26, 878, 84, 39, 118, 89, 91, 112, 105, 39, 133, 37, 149, 37, 159, 33, 331, 37, 148, 35, 195, 36, 185, 2, 3, 2848, 74, 74
I also discovered that every action in system, change of process and change of procesor frequency (because it oscillate between 2000MHz and 3200 MHZ) generate FPS jump (between 3 to 12000!!!)
And... when i set max FPS to 59 or smaller... it not stutter but... you can see typical for vsync when it's off video artifacts.
Any video card settings don't help. Any "adaptive vsync" or something... The problem is also when i delete everything from my code and only black screen is set...
I really don't want to use full power of CPU and GPU all the time when someone play game... Especially if this person play on laptop.