FPS issues in platformer

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.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: FPS issues in platformer

Post by molul »

I'm not totally sure, but I think the problem might be on the low end computer and not in the high end one. However, I'm a Löve beginner, so you'll have to wait for someone with more knowledge to help you with this.

Sorry for not being so helpful :(
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: FPS issues in platformer

Post by kikito »

That "sophisticated way" that included update logic inside love.draw is wrong. Probably it would be better to remove it from the wiki.
When I write def I mean function.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: FPS issues in platformer

Post by molul »

Back to this topic, I removed those lines I found in the wiki and everything went fine, but today I tested my project in another laptop and it runs at 70fps, and its monitor refresh rate is 60Hz, so it's not a matter of vsync (unless it's a bug).

So, what's the proper way to limit fps to a certain value? I already use dt in my update functions, by the way.

PS: the funny thing is that the computer in which the game runs faster is a low-end one (lol).


EDIT: it was a problem with Nvidia drivers. I updated to the latest version and vsync works like a charm :D
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: FPS issues in platformer

Post by T-Bone »

Optimally, your game shouldn't NEED vsync to work. Vsync doesn't work well on all hardware. Even my computer with an i5 @ 4*3.2 GHz becomes a sluggish slug when it tries to chomp a LÖVE game with vsync on. With proper use of dt, a platformer should work just fine even if the framerate goes crazy. Try to turn off vsync, and find out what goes wrong. A typical beginner error is to multiply by dt twice, often on different lines.

The only games that absolutely need a constant FPS on all computers are some games where split second timing is important, like a competitive fighting game. A platformer requires timing as well, but not the kind of split second accuracy we're talking about here. I'm pretty sure Super Meat Boy doesn't vsync on my computer and it runs like a dream.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: FPS issues in platformer

Post by molul »

Well if I turn vsync off, my game runs more or less at 600fps.

I'd like to do my game time-based, not frame-based as it is now. Anybody knows of a good example to start from?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: FPS issues in platformer

Post by kikito »

You already know about dt, don't you?

https://love2d.org/wiki/dt
When I write def I mean function.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: FPS issues in platformer

Post by molul »

I knew about its existence, but not much about its use. Is it as easy as just multiplying any movement (player, scroll, tiles) by dt?


EDIT: I think I got it. I've also remembered that in the beginning I discarded using this approach because I found the game was slower, but now I see it wasn't because it was consuming more CPU. The movements are slower, yes, but consistent. If I turn vsync on and off I see exactly the same speed in animations and movements, in 60FPS and in 600FPS, so I guess I'll see the same on < 60FPS (but it will cut some frames). Now I just need to re-adjust my code increasing the speed and acceleration values until it moves as before. Cool!
Last edited by molul on Mon Feb 27, 2012 3:09 pm, edited 1 time in total.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: FPS issues in platformer

Post by MarekkPie »

Yes. Here's the math behind it for evidence.

If you were to simply add your speed to your character's position every time update is called, then you are not moving at \(speed\frac{\text{pixels}}{\text{second}}\), but rather \(speed\frac{\text{pixels}}{\text{second}}*FPS\). In order to combat the \(FPS\), you need to multiply it by it's inverse, \(dt\). So \(speed\frac{\text{pixels}}{\text{second}}*FPS*dt=speed\frac{\text{pixels}}{\text{second}}*FPS*\frac{1}{FPS}=speed\frac{\text{pixels}}{\text{second}}\).
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: FPS issues in platformer

Post by molul »

Thanks for the explanation, I finally got it :D

Wow, how have I lived without using this? ^^ I hope the OP finds this helpful as well :)

EDIT: wow, this is being a bit tough. Having an acceleration variable complicates things a lot :( Well, it'll take me some time to readjust the physics.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests