LibGDX Stuttering/Jumping Movement, TiledMap, no Delta Timing

It’s jumpy and warpy, not all the time, but I’d say 95% of the time when moving.

I’m using:

OrthographicCamera camera;
TiledMap map;
OrthogonalTiledMapRenderer renderer;

My rendering method is simply:


@Override
public void render(float delta)
{
	if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) 	currentX -= moveSpeed;
	if(Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) currentX += moveSpeed;
	if(Gdx.input.isKeyPressed(Keys.DPAD_UP))) currentY += moveSpeed;
	if(Gdx.input.isKeyPressed(Keys.DPAD_DOWN)) currentY -= moveSpeed;

	Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1);
	Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

	camera.position.set(currentX, currentY, 0.0F);
	camera.update();
	
	renderer.setView(camera);
	renderer.render();

	fpslogger.log();
}

Can anyone offer some help? I’m having a rough time getting this to just simply move a camera around a TiledMap, I haven’t added anything but this!

Apparently you know what delta timing is, so why don’t you just implement it? Also, try checking what kind of fps you’re getting.

In your topic it says “no Delta Timing” Why is that? Have you tried using delta for this?


@Override
public void render(float delta)
{
--   if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT))    currentX -= moveSpeed;
++  if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT))    currentX -= (moveSpeed * delta);
   if(Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) currentX += moveSpeed;
   if(Gdx.input.isKeyPressed(Keys.DPAD_UP))) currentY += moveSpeed;
   if(Gdx.input.isKeyPressed(Keys.DPAD_DOWN)) currentY -= moveSpeed;

   Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1);
   Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

   camera.position.set(currentX, currentY, 0.0F);
   camera.update();
   
   renderer.setView(camera);
   renderer.render();

   fpslogger.log();
}

[EDIT]
Looks like Jimmt beat me to this one. Also if you multiply by delta you will have to increase the move speed values since delta is such a small number.

I’ve done this as well with delta, but the issue remains. I didn’t use delta thinking that there would be less room for error as each render it’d move a set pixel amount.

FPSLogger shows ~60FPS.

I think the reason it bugs out with delta timing is because of the delta spiking up sometimes.

For example: http://pastebin.com/CBZu2PtV

In the entire data sample above, we can see 0.016 - 0.017, with 0.033 showing up twice. Not sure why it’s spiking up, nothing different is being called other than this map rendering.

Delta time is the time between frames, so it’s never going to be 100% consistent. A range of 0.001 delta time is perfectly normal.

related to vsync?

It’s bumping up from 0.016 to 0.030 randomly with vsync.

I disable vsync and I still get chunked movement 90% of the time, which is visibly noticeable.

try a profiler like visualvm and see what’s happening on the frame. It could be something external to your program in which case you won’t see anything.

I’ve had issues with the same thing before. I would code my game on my computer, and then go test it at school or a friends computer and suddenly the “lag spikes” disappeared. I don’t know if the issue is hardware related or what, but LibGDX has never played nicely with my computer. Maybe it was poor coding, I don’t know.

I’ve given my .jar to a friend to test out, as well as I have tested it out on my gaming PC and a laptop.

My PC and laptop is using an AMD processor, my friend is using an Intel processor, we both get the chunky camera movement, so I don’t believe it is isolated to our computers.

Not sure how I would use VisualVM to even test this out as I believe the code I use to render the map is extremely small, I can’t really see how something would be affected by this. I’ve tried out 3 different maps, so I don’t think it is something map related.

Is the render method the only thing you are doing every frame? Maybe you’re binding textures or something?

The render method in the first post is the only render method I am using :confused:

I have kinda same looking problem on my PC… It happens on top 1/4 of the screen. It only happens when game window is at the upper most position on screen. If I move game window down, shuttering disappears o-o

Hmm, I believe this is some sort of LibGDX thing with TiledMap?

I’ve also made a little rendering loop myself to render and it’s still the same jitteryness.

Here it is if you want to take a look: http://pastebin.com/xivG7mrN

I’ve seen a few games with LibGDX, how are you guys getting past or just not even coming across this issue? It’s frustrating :persecutioncomplex:

this might not help, but i had a similar problem once when my laptop was on power saver mode and for some reason the cpu time% allocated to my program was lowered by windows. it made the frame rate very erratic.

ah you youngsters.
ok now listen
implementing delta time correctly is very very hard. it will make your problems worse. the reason you would use it would be if you expect your game to go above or under 60 fps frequently. if not, using a constant delta time is absolutely recommended. either set it to 0.016 or ignore it all together.
this board is old and there is a plethora of information, you may wanna read some of it.

bottom line, if this is pc only: cap fps to 60 make sure it doesnt go below, if it does then the game is slower, which is fine since it means the pc is too weak to play your game anyway.

As I’ve mentioned earlier in this thread and in the title of this thread…

LibGDX Stuttering/Jumping Movement, TiledMap, no Delta Timing

this is a common issue

check out gameloops and stuttering on jgo
its not really that much of an issue with libgdx vsync

generally speaking if more stuff is going on the less it stutters; that is my experience. I think it has to do with the fact that when the cpu isnt very busy these spikes are more noticable.
So my tip for is just keep developing the game and check back later

Alright, thanks! So the best bet is to just enable vsync and keep on going?

yeah.
I mean gameloop stuff you can still change afterwards