Page 1 of 1

About using SpriteBatch

Posted: Fri Sep 16, 2016 5:42 am
by scoobyff666
Hi. I'm new to the concept that a SpriteBatch represents. What I could understand hitherto is that I can minimize the number of "draw" operations by using a SpriteBatch to make a lot of copies of the same sprite and then draw all of them with a single draw call.

If I'm right about that, then comes the question: I know I can get a huge speedup when I used a SpriteBatch to draw a map from a tileset that is a texture atlas but, as far as I understand, if instead of that each tile is in a different file, then I need to have a SpriteBatch for each of the files and call a lot of draws, making my program slow. Is this right? And if it is, why? I mean, is it not possible to make something that allows me to reduce the number of draws if I'm using lots of different texture files? And does that mean that if I had a HUGE file with all textures that I need to draw then I would be able to draw everything with a single SpriteBatch and the performance would be optimal?

I wonder if this subject sounds too obvious to you guys, but I still can't get my head around this.

Re: About using SpriteBatch

Posted: Fri Sep 16, 2016 9:02 pm
by Sulunia
Not sure if i understood, but you could in a loading screen draw your map to a canvas and then use it as a single giant texture. Probably not a good approach, perhaps someone else can provide a better answer!

Re: About using SpriteBatch

Posted: Sat Sep 17, 2016 12:56 am
by s-ol
scoobyff666 wrote:And does that mean that if I had a HUGE file with all textures that I need to draw then I would be able to draw everything with a single SpriteBatch and the performance would be optimal?
Exactly. Look up 'spritesheet' maybe. This is what 2d games (and websites btw) were made with for a long time btw.