Taking too much time to draw

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
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Taking too much time to draw

Post by pauls313 » Thu Sep 08, 2016 7:05 pm

My code iterates through a tile table every frame to draw it, but it's taking way too long. It's running at 10FPS.
(688.88 KiB) Downloaded 61 times

User avatar
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Taking too much time to draw

Post by raidho36 » Thu Sep 08, 2016 8:44 pm

Well you're rendering 10 000+ objects without using batches or anything of the sort, so pretty much every draw operation translates to at least one GPU render call. And 10k+ draw calls is insane number, GPUs normally deal with few tens at most.

You need to use render batching.

Party member
Posts: 223
Joined: Mon Aug 29, 2016 8:51 am

Re: Taking too much time to draw

Post by KayleMaster » Thu Sep 08, 2016 9:13 pm

Definitely need to batch those sprites (look up spriteBatch love2d).
I'm using 9 spriteBatches and I am drawing 36864 tiles (32*16) in my game at 512 fps on a low end pc. Basically, the difference is, that it's 1 draw call instead of 10000 and that's what makes it faster. However they can be tricky to implement.

User avatar
Party member
Posts: 3040
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary

Re: Taking too much time to draw

Post by zorg » Thu Sep 08, 2016 11:03 pm

I also looked at the code, and apart from not being indented at all, you also redefine love.keywhatever each time love.update is called. That's not how it works, and that's not how you should do it; Define it outside love.update. Or use the isDown function in update.
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
Posts: 12
Joined: Sat Oct 10, 2015 8:17 pm

Re: Taking too much time to draw

Post by bjornbytes » Fri Sep 09, 2016 4:00 am

I just made something that might help with this: glance. You basically wrap your draw operations in glance.render() which will save things to a Canvas if they don't change very much -- it's a tradeoff between draw calls and texture memory. If you're able to use a SpriteBatch though, that would be the best way to do things.

User avatar
Party member
Posts: 908
Joined: Sun Sep 02, 2012 10:46 pm

Re: Taking too much time to draw

Post by Karai17 » Fri Sep 09, 2016 10:11 am

If you're using a tilemap, you shoudl check out STI and try using Tiled to make your maps. This is very much a solved problem.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests