Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So what do I mean by layered sprites? Layered Sprites are Sprites that consist of multiple layers, e.g. you have sprite sheets for the basic Body, the Head, Clothes, Weapons, etc.

Well now I wanted to know how you would draw this in the most efficient way; right now the idea is to use vertex buffer objects (VBOs), but I heard that it is expensive to change the textures in a VBO...

So what would be the correct way to draw them? My idea right now would be to draw the Map tiles first (with a texture atlas), then I would draw all the basic bodys, then the heads, then clothes, and then the weapons. Would that be the best way or is there a more efficient way?

I also thought of using vertex arrays instead of VBOs, but as far as I know they are deprecated...

share|improve this question
"doing X is expensive" shouldn't stop you from trying it to see how expensive actually is in your application – ratchet freak Feb 6 '14 at 9:37
That isn't what I asked. If you have a Sprite with e.g. 10 layers und you want to draw it on a Map with let's say 500x500 Tiles and 250 Sprites that would be nearly 250000 draws per frame. I just want to know what the best way would be to draw something like that. – user41845 Feb 6 '14 at 10:44
what I'm saying is that you should at least try and see how it affects performance, high end 3D games use dozens of different textures and still get 100 FPS – ratchet freak Feb 6 '14 at 11:24
I'm planning how to best do it before I start implementing, that's why I asked. – user41845 Feb 6 '14 at 12:09
Beyond asymptotic complexity analysis, computer science still cannot offer a reliable way of predicting your code's performance. If you can't quickly write the code to test it, you've still got a lot of programming to learn -- and hence should write a test with all the more reason. – Anko Feb 6 '14 at 13:45
up vote 0 down vote accepted

Pack sprites into large texture atlases, and have a quad (VBO) per sprite (for each individual frame). When you want to draw a certain sprite, you draw the appropriate quad on screen, rather than changing the texture for a quad. Sort the draw calls by layer, and that should be all you need.

And to clarify:

Rather than having, say, headQuad, for which you change texture depending on what head and what frame you want, you instead have monsterHeadQuad1, monsterHeadQuad2, monsterHeadQuad3, heroHeadQuad1, heroHeadQuad2, and so on. The numbers represent the animation frame.

If you have lots of the same sprite on screen, look into instanced rendering.

There are plenty of hacks for speeding up the process, but I'd worry more about getting it working than getting it running at 1000+ frames per second.

share|improve this answer
Wouldn't it be better if you change the texture region in the headQuad instead of having multiple quads for each animation frame? – user41845 Feb 6 '14 at 13:05
You can store millions of quads in video memory; use it to your advantage! There's going to be a small performance cost every time you modify a quad (update the texture coordinates for each vertex), as opposed to just drawing an existing quad. – Fault Feb 6 '14 at 13:33
I see, I thought that it would be limited. – user41845 Feb 6 '14 at 13:43

Probably the most efficient method would be to draw all the sprites using the same texture at once. You can also save some time transferring memory to the GPU by using a geometry shader or instancing that only takes inputs like position, scale, and orientation, and builds the sprite triangles/quads from that.

You can preserve sprite layering by using depth buffering, which is arguably a better method all-around than temporal layering.

share|improve this answer
So you say it would be better to have a big texture atlas with everything in it? And by depth buffering you mean Z-buffering? – user41845 Feb 6 '14 at 12:24
Not necessarily. As long as you draw all the sprites using the same texture at once, you will see huge performance gains as binding a new texture is quite slow. – Boreal Feb 6 '14 at 13:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.