Quad vs SpriteBatch

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
Malmik
Prole
Posts: 5
Joined: Fri Aug 03, 2018 3:01 pm

Quad vs SpriteBatch

Post by Malmik »

Hello, I want to make terrain in my game using tileset. What will be different, when instead of adding quads to spriteBatch, I will draw them to canvas first, then draw that canvas every frame?
User avatar
ChicoGameDev
Citizen
Posts: 70
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Quad vs SpriteBatch

Post by ChicoGameDev »

Hello,

I just done the exact same thing this very morning!

I can suggest you to preRender your tilemap on a canvas and then as you said, render the canvas each frame :

Code: Select all

function preRender()
    love.graphics.setCanvas(canvas)
        for i = 1, #map do
            self.map[i]:draw()
        end -- for
    love.graphics.setCanvas()
end -- function
Assuming you will manage your tile as separate object with their own :draw() function :) But it can be 2 for loops with x and y coordinates :D

then in your draw() :

Code: Select all

love.graphics.draw(canvas)
It's a good practice for all the "static" stuff or at least everything you could draw that does not change every frame! Watch out if you'll need animated tiles...

Regards
Lionel Leeser

Luven : https://github.com/chicogamedev/Luven

--

Always keep Game Dev as a passion.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Quad vs SpriteBatch

Post by pgimeno »

Can you rephrase the question, please?
Malmik
Prole
Posts: 5
Joined: Fri Aug 03, 2018 3:01 pm

Re: Quad vs SpriteBatch

Post by Malmik »

Hi, sorry for poor english :nyu: ! I was contemplating:

What will change (in means of efficiency and speed of course) when instead of using spritebatch to draw my quads, I will "prerender" them to canvas and draw every frame as ChicoGameDev showed?

Ps. Thanks Chico for sooo pleasant response! :awesome:
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Quad vs SpriteBatch

Post by pgimeno »

Ahh okay, thanks for the clarification. Switching canvas is slow, so I would expect that drawing to a canvas first will be a bit slower than drawing the spritebatch directly.

Note that LÖVE 11+ automatically creates spritebatches when you draw things without changing texture.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Quad vs SpriteBatch

Post by zorg »

Drawing quads to canvases (or directly to the screen, which is also an option) is batched as of version 0.11 (as long as you don't mess with the graphics state too much (except transforms and color), or change the image you're drawing) so they should be as performant as Spritebatches, whose contents get drawn all at once... unless quads break batching, in which case, Spritebatches will be faster.

But pgimeno's also right in that canvas switching does incur a bit of an overhead.
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
ChicoGameDev
Citizen
Posts: 70
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Quad vs SpriteBatch

Post by ChicoGameDev »

You're welcome Malmik,

Actually yes switching canvas is probably bad but actually mind the fact that my tilemap never change so when I procedurally generate my dungeon, I prerender it once on my canvas and then I just draw it.

So I assume I'm reducing draw calls by a lot by doing so and there is no canvas switching. Or did I get something wrong ? :o


pgimeno wrote: Fri Feb 15, 2019 11:45 am Note that LÖVE 11+ automatically creates spritebatches when you draw things without changing texture.
Thanks for info :)


Regards
Lionel Leeser

Luven : https://github.com/chicogamedev/Luven

--

Always keep Game Dev as a passion.
Post Reply

Who is online

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