Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I use an OrthogonalTiledMapRenderer:

renderer = new OrthogonalTiledMapRenderer(world.getMap());

and I wonder if there is a differnce between this call:

renderer.getSpriteBatch().draw(sprite, sprite.getX(), sprite.getY());

and this:

sprite.draw(renderer.getSpriteBatch()); 

If there is a difference, what is it?

share|improve this question
    
While there's no difference between the two, I do want to point out something for future reference: OrthogonalTiledMapRenderers have a SpriteBatch in the class, meaning that if you have a SpriteBatch to render everything and then you create a OrthogonalTiledMapRenderer to render your map, you'll come up with some pretty random rendering bugs. An easy fix is to instantiate the OrthogonalTiledMapRenderer like so: OrthogonalTiledMapRenderer mapRenderer = new OrthogonalTiledMapRenderer(map, alreadyExistingSpriteBatch); –  hasherr Aug 11 at 16:47
    
Sprite is a subclass of TextureRegion. I found this helpful when thinking about drawing Sprites. –  Brandon Aug 12 at 20:23

1 Answer 1

I found this in the libGDX source code, in class Sprite.java

public void draw (Batch batch) {
    batch.draw(texture, getVertices(), 0, SPRITE_SIZE);
}

So no, no difference. It shows Sprite.draw is only syntactic sugar for the longer version you posted.

share|improve this answer

Your Answer

 
discard

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.