Page 1 of 1

FPS issue with simple box2D game

Posted: Wed Oct 19, 2016 3:56 am
by Aaron51
Hey guys!

I just started working with love today but I have been struggling with this little FPS issue for a few hours. I know there are a lot of threads about FPS problems on this forum, but I couldn't find a solution after trying many of them. When I run the game, it is smooth as butter for about 10 seconds. After that, it will start to lag. It will not lag outrageously but it is definitely noticeable.

I draw the FPS on the screen of the game and it stays at 60 throughout since I limit it in love.update(). I also checked the cpu usage in Task Manager; it uses 2% of my cpu and about 34 MB of ram. I also checked garbage collection. I put the line collectgarbage("stop") in love.load() and it did not fix the issue.

I will attach my .love file to this post. It is not too complicated. If any of you have any guidance or ideas, please don't hesitate to let me know!
WormWhip.love
(2.34 KiB) Downloaded 143 times
controls
a -> counterclockwise rotation
d -> clockwise rotation

Thanks,
Aaron

Re: FPS issue with simple box2D game

Posted: Wed Oct 19, 2016 6:06 am
by ivan
Good job on using a fixed time step.
First of all, getFPS is the number of frames that are drawn per second.
The hard-coded "physics interval" has nothing to do with drawing on the screen so your FPS will max out at 60 due to vsync.
To check your physics frame rate, you can use: physicsFrameRate = 1/(interval*steps)
I ran a profiler on your code and it didn't show any glaring bottlenecks.
The game runs fine so the lag may be caused by some other software on your machine.
collectgarbage("stop") in love.load() and it did not fix the issue.
Generally, I don't recommend turning off the GC in Lua.
It probably doesn't matter in this case, since love2d seems to control the garbage collection internally.

Good luck.

Re: FPS issue with simple box2D game

Posted: Wed Oct 19, 2016 9:11 am
by raidho36
LÖVE does manual memory management internally, but once it's out in the Lua it's up to GC to handle it.