What is a spritebatch?

A port replacing OpenGL and OpenAL with SDL. Now defunct.

Moderator: nLÖVE Team

Locked
iamwil
Prole
Posts: 11
Joined: Fri Aug 19, 2011 8:53 pm

What is a spritebatch?

Post by iamwil »

What is a SpriteBatch? From the reference API, I don't quite get what it is. Googling didn't seem to quite help either. Can anyone explain to me what a SpriteBatch is?
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: What is a spritebatch?

Post by miko »

iamwil wrote:What is a SpriteBatch? From the reference API, I don't quite get what it is. Googling didn't seem to quite help either. Can anyone explain to me what a SpriteBatch is?
http://love2d.org/wiki/Tutorial:Efficie ... _Scrolling
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
slime
Solid Snayke
Posts: 3129
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: What is a spritebatch?

Post by slime »

The regular way to draw things onto the screen (using love.graphics.draw) is to send the image and position to the GPU every time you draw anything, even if you're using the same image multiple times in a row. Sending information to the GPU can become a huge bottleneck, especially if that information doesn't actually need to be sent. Spritebatches help with this problem by specifying an image to draw and then saving all the locations you want to draw it at to the GPU's VRAM for use at a later time. Then it only has to send the image once and tell the GPU to use the locations it saved.
This can have huge performance benefits if, for example, you have an image of background tiles, because then you can just make a spritebatch with the image, add the locations of the tile quads, and then draw the entire thing in one go at a later time, using the saved position data, instead of re-sending the image and related data over and over and over.
iamwil
Prole
Posts: 11
Joined: Fri Aug 19, 2011 8:53 pm

Re: What is a spritebatch?

Post by iamwil »

Ahh, thanks for the explanation. I didn't know it was related to Tile scrolling as well.

Wil
Locked

Who is online

Users browsing this forum: No registered users and 9 guests