Search code examples
libgdxsprite

What is the difference between batch.draw and sprite.draw in LibGDX?


Both of the methods look similar, but I'm having a hard time understanding when to use these. I just want to know where to use these two, e.g. sprite.draw(batch) and batch.draw(sprite,x,y).


Solution

  • One is for drawing a texture the other is for drawing a sprite.

    spriteBatch.begin();
    spriteBach.draw(texture, x,y);
    spriteBatch.end();
    

    and

    spriteBatch.begin();
    sprite.draw(sprite,x,y);
    spriteBatch.end();
    

    Link to relevant libgdx wiki: Spritebatch, Textureregions, and Sprites