Hello again, LÖVErs. I have a question about keeping the framerate consistent and making things run smooth. What are some methods for doing this? I have been trying to figure out how not to have so many pictures on the screen (so that it doesn't eat up CPU cycles). When one of the enemies in my little game is destroyed, for example, I just have them moved off the screen. I have been wondering about how to remove the enemy picture, data and all.
That would help to speed things up, but I'm sure there are better ways to make this more efficient, like we always try to do.
Managing a consistent framerate
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Managing a consistent framerate
Booted, suited, and ready to get executed.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Managing a consistent framerate
framebuffers or spritebatches are good ways to draw backgrounds while saving on framerate. As of LÖVE 0.7.1, love.graphics.print/love.graphics.printf are very inefficient and can cause large performance drops, but that will be improved in LÖVE 0.8.0.
If you're doing a lot of heavy lifting in love.update it can be a good idea to only update that portion of the update code every 30 or 60 frames.
There are always ways to improve performance, but beyond using the right tools for the job (framebuffers for example) don't spend too much time during early development optimizing, as you may have to rewrite large portions of your code later anyway.
If you're doing a lot of heavy lifting in love.update it can be a good idea to only update that portion of the update code every 30 or 60 frames.
There are always ways to improve performance, but beyond using the right tools for the job (framebuffers for example) don't spend too much time during early development optimizing, as you may have to rewrite large portions of your code later anyway.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Managing a consistent framerate
When you don't need a certain image, just don't draw it -- not even off screen. That helps.Ertain wrote:When one of the enemies in my little game is destroyed, for example, I just have them moved off the screen. I have been wondering about how to remove the enemy picture, data and all.
If you are really sure you don't need the image any more, you can just clear all references to it, and Lua will collect it automatically.
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Managing a consistent framerate
Yeah. Drawing off the screen is just as slow as drawing on the screen, so to have the best possible framerate, make your game only draw what's visible.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Managing a consistent framerate
Of course, sometimes it can be slower to check for whether an image is in the screen area or not than to just draw it without any checks.Taehl wrote:Yeah. Drawing off the screen is just as slow as drawing on the screen, so to have the best possible framerate, make your game only draw what's visible.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Managing a consistent framerate
The absolute best way is to use a method that doesn't even have to bother checking for the location of an image. It scales much better.slime wrote:Of course, sometimes it can be slower to check for whether an image is in the screen area or not than to just draw it without any checks.
Help us help you: attach a .love.
Re: Managing a consistent framerate
Thanks for the help, guys. I shall not use the in-game print statements and stop drawing the images. But the framebuffers will be a problem, because they don't work on all OSes. So I'm going to have to at least check for the framebuffers and stuff.
Booted, suited, and ready to get executed.
Re: Managing a consistent framerate
I would say those are standard problems. I do agree with what was said before, and I would add:Ertain wrote:Hello again, LÖVErs. I have a question about keeping the framerate consistent and making things run smooth. What are some methods for doing this? I have been trying to figure out how not to have so many pictures on the screen (so that it doesn't eat up CPU cycles). When one of the enemies in my little game is destroyed, for example, I just have them moved off the screen. I have been wondering about how to remove the enemy picture, data and all.
That would help to speed things up, but I'm sure there are better ways to make this more efficient, like we always try to do.
- don't do anything you don't need (calculations, drawings, etc)
- if you really have to do it, do it only once (move to love.load(), memoize, cache, etc)
- if it cannot be done once, do it only as frequent as it really is required (eg, change the value of timer every second, not every frame)
- move your busy code out of the main loop (move long-running operations to other threads, like love.thread)
- put more RAM (there is usually tradeoff between CPU and RAM usage)
- use clever algorithms (eg, do not recalculate the whole scene, only the part which really has changed, use clever sorting algorithms, use object partitioning for collision detection)
- check for efficient lua usage: avoid creating and destroying objects which have to be garbage-collected (so reuse your tables instead of recreating new ones)
- profile your code (find the slowest part and try to optimize it)
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Managing a consistent framerate
At least when drawing rectangles, I found that to be quite the opposite. When a couple hundred rectangles were on-screen, there was a slow down in framerate to the 200s I think. Then it went back up to the high 400s when not so many were around. Again, when drawing rectangles, I found by doing checks on what to draw, I had a frame rate drop of about 40-50 when drawing about 15-20 rectangles. But, it might different for images.Taehl wrote:Yeah. Drawing off the screen is just as slow as drawing on the screen, so to have the best possible framerate, make your game only draw what's visible.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Managing a consistent framerate
I was talking about drawing images (and I assume the same would be true about framebuffers, quads, and spritebatches). I don't know about simple things like rectangles.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests