简体   繁体   中英

LibGDX: Whats the difference between drawing by Sprite and drawing by SpriteBatch?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM