Reputation: 559
While programming with LibGDX I noticed that there are two methods to draw a sprite. But first of all that is my situation:
(...)
SpriteBatch batch;
Sprite testSprite;
(...)
batch = new SpriteBatch();
testSprite = new Sprite(new Texture("test.png"));
(...)
The first method is from the SpriteBatch:
(...)
batch.draw(testSprite,...);
(...)
The second method is from the Sprite itself:
(...)
testSprite.draw(batch);
(...)
What are the differences between this methods? Hope you can help me :D ~ Henri
PS: I´m beginner :D
Upvotes: 2
Views: 337
Reputation: 20140
testSprite.draw(batch);
Sprite
holds the geometry, color, and texture information for drawing 2D sprites using Batch. A Sprite has a position and a size given as width and height.
In a simple way you can say Sprite is a complete package(where to draw and with different factor like size, scale factor,rotation..).
But If you use
batch.draw(testSprite,...);
Then you've to instruct position, size and another factor that required for drawing by another argument of draw(..)
method.
Upvotes: 1