Page 1 of 1

Laggy keyboard movement

Posted: Sun Jun 03, 2012 9:38 am
by mcjohnalds45
When making a graphic move across the screen with frame rate independent movement with

Code: Select all

if love.keyboard.isDown("w") then
	y = y - 200 * dt --dt is the delta time
end
if love.keyboard.isDown("a") then
	x = x - 200 * dt
end
if love.keyboard.isDown("s") then
	y = y + 200 * dt
end
if love.keyboard.isDown("d") then
	x = x + 200 * dt
end
The movement of the graphic appears to have inconsistent lag, but when moving a graphic across the screen with the typical

Code: Select all

if love.keyboard.isDown("w") then
	y = y - 5
end
if love.keyboard.isDown("a") then
	x = x - 5
end
if love.keyboard.isDown("s") then
	y = y + 5
end
if love.keyboard.isDown("d") then
	x = x + 5
end
The movement is totally smooth, is it something to do with the delta-time being inaccurate on 32 bit machines or something?

Excluding that minor hiccup, the love framework is looking really awesome, I can't wait to make my ninjas vs civil war soldiers game!

Re: Laggy keyboard movement

Posted: Sun Jun 03, 2012 8:28 pm
by bartbes
It's probably related to drawing on non-integer coordinates, what happens if you round the coordinates before drawing?

Re: Laggy keyboard movement

Posted: Sun Jun 03, 2012 9:02 pm
by Robin
To be honest, I don't see any difference.

Re: Laggy keyboard movement

Posted: Sun Jun 03, 2012 9:50 pm
by Nixola
I see a more laggy movement when moving without dt...

Re: Laggy keyboard movement

Posted: Mon Jun 04, 2012 1:31 am
by mcjohnalds45
Thanks for the suggestion bartbets, but it didn't work, I'm assuming you meant putting

Code: Select all

x = math.floor(x)
y = math.floor(y)
at the end of the update function, must be something wrong with the love framework, the lag is very noticeable on my crappy windows xp os, oh well I'll just stick with the good ol' simple way.

Re: Laggy keyboard movement

Posted: Mon Jun 04, 2012 7:25 am
by bartbes
That's not what I meant, because that will make movement incorrect, you need to round (down) what you pass to love.graphics.draw, not what you manipulate.