Jittery 2D Scrolling

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
noegddgeon
Prole
Posts: 6
Joined: Mon May 08, 2017 6:22 pm

Jittery 2D Scrolling

Post by noegddgeon »

Hello all,

I've noticed that simple 2D scrolling in my various projects seems to be a bit jittery on my Macbook Pro (which has decent specs; 2.8 GHz i7, 16 GB RAM, Intel Iris 1.5 GB). I'll link a couple of the files from GitHub here on a simple RPG engine I'm working on that are pertinent to the rendering:

https://github.com/coltonoscopy/jrpg-en ... e.lua#L316
https://github.com/coltonoscopy/jrpg-en ... p.lua#L116

I don't think the engine is doing anything too fancy that would cause it to be jittery? I'm using the Push library to help with virtual resolution handling and using math.floor to round down floating-point coordinates during the rendering phase where needed so as to avoid glitchy rendering since it's using a limited-resolution texture, which causes funkiness for non-integral positioning when drawing, but the jerkiness seems present if not worse even if that's not happening. The frame rate seems to be hovering around 60 FPS without any difficulty too, so I'm a bit stumped as to what might be going on :o. Any help is greatly appreciated! :)

Best,
Colton
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Jittery 2D Scrolling

Post by erasio »

I've seen this a while ago already. Also when using floor.

My first guess would be that floor is messing with you.

Assuming you scroll 1.3 pixels per frame. Flooring will result in the location being:

0
1
2
3
5
6
7
9

Every now and then jumping two pixels instead of one. No guarantees. I don't have any visuals here to go by. So I can't tell for sure. But it might be part of the issue. Especially with minor framespikes.

You could try to use love.timer.getAverageDelta( ) instead. Which samples dt across a second and gives you the average. So your game time is slightly off real time. But time within a frame will be more consistent and you'll never completely drift away from the real time passed. It'll just be minorly distorted when frame spikes happen.

Also check out if you have vsync enabled. If not. Try that too!
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Jittery 2D Scrolling

Post by zorg »

You do a wonderful job math.floor-ing the camera position with which you translate the coordinate system by... then fail to do so here:

Code: Select all

-- ExploreState.lua#L326
-- render the map around the player center
self.map:render(self.player.x, self.player.y)
Now if your rebuttal would be that you already floor those two when you calculate the logic, then you're doing it wrong; logic should be accurate, you only round rendered things.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
noegddgeon
Prole
Posts: 6
Joined: Mon May 08, 2017 6:22 pm

Re: Jittery 2D Scrolling

Post by noegddgeon »

Hi erasio,

Thanks so much for the reply! I implemented using an average delta time and turned on vsync per your suggestions, as well as fine-tuned the movement speed of the player, and that actually did help! However, I'm noticing that now the problem has gotten a little more refined: smooth scrolling works perfectly, but only when moving right and down; moving up and to the left is still a little bit jerky for some reason. Do you know why this might be? Currently movement is implemented using tweens between tile positions, so that the player is essentially locked to a grid in the style of classic Final Fantasy games, etc. Thanks for your time and help!

Best,
Colton
noegddgeon
Prole
Posts: 6
Joined: Mon May 08, 2017 6:22 pm

Re: Jittery 2D Scrolling

Post by noegddgeon »

zorg wrote: Fri Oct 20, 2017 6:20 pm You do a wonderful job math.floor-ing the camera position with which you translate the coordinate system by... then fail to do so here:

Code: Select all

-- ExploreState.lua#L326
-- render the map around the player center
self.map:render(self.player.x, self.player.y)
Now if your rebuttal would be that you already floor those two when you calculate the logic, then you're doing it wrong; logic should be accurate, you only round rendered things.
Hi zorg,

Thanks for your reply! I'm not sure I follow; the Map is always rendered as a fixed grid in the world space, just with certain tiles conditionally rendered based on what we approximate the view window to be; the X and Y there are floats representing the character's tile position essentially (not actual X/Y coordinates). Trying your fix actually causes some of the lower tiles in the map to not render while moving because the math for calculating visible tiles no longer works right, while not fixing the jerkiness. But maybe I'm missing something, so if you wouldn't mind elaborating, I'm curious!

Best,
Colton
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 52 guests