Make speed constant no matter the FPS

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
HolyMolly
Prole
Posts: 1
Joined: Wed Dec 20, 2017 10:28 pm

Make speed constant no matter the FPS

Post by HolyMolly »

In most languages/engines/frameworks, I could just write the movement code like this:

x = x + (speed * dt)

And it would work fine. But in Love2D, the dt changes nothing. If it's at 60FPS, it will move at a certain speed. If it's 20FPS, it will be much slower. What can I do?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Make speed constant no matter the FPS

Post by Nixola »

You could show us some actual code, or even better upload a working .love file that showcases your issue; the snippet itself looks fine.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Make speed constant no matter the FPS

Post by zorg »

if you put dt as a parameter into the love.update callback (or whatever function you put that code in, while passing love.update's dt into it) it should work. As Nixola said, post a bit more code.
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.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Make speed constant no matter the FPS

Post by Jasoco »

In my experience, dt has always worked as it should. As was said, provide an example that gives us the result you're seeing and we'll tell you if anything is wrong.

Also maybe your system specs.
User avatar
SirRanjid
Prole
Posts: 39
Joined: Sun Nov 19, 2017 1:44 pm
Contact:

Re: Make speed constant no matter the FPS

Post by SirRanjid »

My guess would be you're using the dt of the update function inside the draw.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Make speed constant no matter the FPS

Post by Jasoco »

As has been mentioned, as long as you pass dt into every function you place in update that has anything to do with movement or speed or whatever, it should work fine. And don't try to use it in love.draw as it won't work, but you can make it work if you absolutely have to by either calling love.timer.getDelta() manually or rewriting love.run to pass dt into love.draw as well and treating it the same. If you have to.
Post Reply

Who is online

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