SpriteBatches

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
piller187
Prole
Posts: 5
Joined: Thu May 21, 2015 4:15 pm

SpriteBatches

Post by piller187 »

I'm not new to game development but not sure if I follow SpriteBatches exactly and want to make sure I understand. I've mostly worked with 3D engines that hide most all details about the gfx card.

I was looking at the following tutorial trying to figure it out. https://love2d.org/wiki/Tutorial:Effici ... _Scrolling

From what I can tell you give a sprite batch an image and tell it the total amount of tiles on it?

Then you create quads which from what I can tell is just data that describes the tiles on the tilesheet.

It seems like we then tell the sprite batch what quads to use and where to draw them, and then in love.draw() we tell the sprite batch to actually do the drawing.

The entire benefit being that when we make a sprite batch the tilesheet image is sent to the gfx card memory and stays there so we aren't sending images there over and over again like "normal" drawing. However, what we do send over and over again is the quad and position information where those quads should go?

I assume each new sprite batch is instantly put in gfx card memory when it's created?

What if my game map needs multiple tilesets to be drawn on screen at once? Like I need 4 tiles from 1 tilesheet and 2 from another? Seems I would need 2 sprite batches (1 for each tileset) and then as I'm looking over my map would I just check what tilesheet/sprite batch it needs and add the quads to that sprite batch and then in love.draw() draw both spritebatches? So if you were to draw only 1 you'd see "holes" in the map but the 2 of them combined makes a full map? How would this handle drawing order requirements of ground layers and foreground layers?
User avatar
nkorth
Prole
Posts: 15
Joined: Sun Sep 18, 2011 8:54 pm
Contact:

Re: SpriteBatches

Post by nkorth »

Yes, a primary advantage is sending the tileset texture to the graphics card less often. However, the other major benefit is doing the same for the actual sprites! A common use case for a SpriteBatch is for a tile-based background, in which case the SpriteBatch is only modified once - when it's created.

If you need multiple tilesets: first consider combining them into one bigger tileset, which would be the best way to simplify use of SpriteBatch. Having multiple SpriteBatches isn't a problem, though - one way some people handle drawing order is to actually have a separate SpriteBatch for each row of the background image, so that player sprites can be sorted in appropriately based on y position. Of course, if all you need is to separate background from foreground, just make two SpriteBatches (or two pairs of SpriteBatches if you're using two tilesets, perhaps.)
Post Reply

Who is online

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