Spritesheet - Single Sprite Confussion

Hey Guys,

I didnt code in like forever and want to start Again.
Now i did read some stuff about Sprites vs Sprite Sheets /Texture Regions and im kinda confussed.
Like in the Past, ive Mostly used Libgdx for my 2d games. But I want to start with lwjgl this time.
Mostly i did draw my Sprites like that :

    public void create () {
        batch = new SpriteBatch();
        Sprite player = new Sprite(xyz); //texture and so on
    }

    public void render () {
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears the screen.
        batch.begin();
        // Drawing sprite her e.g. player.draw(batch);
        batch.end();
    }

Now in the lwjgl git ive found this :

from what i understand in Libgdx i basicly did it like this :

[quote]This is the basic idea behind a sprite batcher. As you can see, using many textures will lead to many draw calls (as the batch will need to flush for each new texture). This is why a texture atlas (AKA sprite sheet) is always recommended; it allows us to render many sprites in a single draw call.
[/quote]
Is that the Case ? And if yes, if i really do start working with Texture Sheets, like the following code, i dont see how its gonna increase the Performance, since it looks nearly the same for me :

... inside SpriteBatch begin / end ...
spriteBatch.draw(region, x, y);

what i mean is, if i do it like this, in the end i also will have many many “spriteBatch.draw(region, x, y);” calls which is like the same.

Thanks in advance Guys,
If i did write crap please bear with me, my coding is reallllyyyy rusty. :wink:

Incorrect.

Loading 1 large texture onto the GPU is more efficient than multiple smaller ones.

TextureRegion in LibGDX inherits from texture, so many regions made from 1 texture is faster than many small textures passed in one after other.

I would have thought so too, + its easier to handle one image variable rather then 100 individual ones

thanks for the answers.

So let me see if i got this right.
if i draw each sprite with “spritexyz.draw” like this :

spritexyz1.draw();
spritexyz2.draw();
spritexyz3.draw();

3 sprites get loaded in the GPU. like seperately.

But if i take the 3 sprites, put them together in one large sprite and then do :


spriteBatch.draw(regionxyz, x1, y1);
spriteBatch.draw(regionxyz, x2, y2);
spriteBatch.draw(regionxyz, x3, y3);

its actually more Performant ? cuz the one sprite gets loaded once in the gpu and the gpu automaticly draws the 3 regions ?

and my second Question is, is this also the Case if i draw the same sprite 3 times like this :


spritexyz1.draw();
spritexyz1.draw();
spritexyz1.draw();

would the Sprite still be loaded into the GPU 3 times ? and i would also get a performance increase by drawing the same region 3 times ?

Thanks in advance for ur answers.

You’re confusing sprite batching with spritesheets/texture atlases. They do different things, both are good for performance.

SpriteBatch doesn’t do anything with texture atlases for you. You need TextureAtlas (surprise!) for that.
You can get them in several ways, either by packing image files together using the texture packer tool ahead of time, or at run time like so: http://www.badlogicgames.com/wordpress/?p=2297 (or see Automatic Packing section of previous link)

Once you have a texture atlas (spritesheet) you can get your sprites from it which then are used as normal:

Sprite gunshipSprite = atlas.createSprite("gunship1");