Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Spritesheet - Single Sprite Confussion  (Read 11159 times)
0 Members and 1 Guest are viewing this topic.
Offline T1663R

Junior Devvie

Medals: 2

« Posted 2015-01-03 23:06:03 »

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 () {; // This cryptic line clears the screen.
        // Drawing sprite her e.g. player.draw(batch);

Now in the lwjgl git ive found this :

from what i understand in Libgdx i basicly did it like this :
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.

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
Offline Gibbo3771

JGO Kernel

Medals: 128
Projects: 5
Exp: 1 year

Currently inactive on forums :(

« Reply #1 - Posted 2015-01-04 18:52:39 »


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.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Ed_RockStarGuy
« Reply #2 - Posted 2015-01-04 18:56:21 »

I would have thought so too, + its easier to handle one image variable rather then 100 individual ones
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline T1663R

Junior Devvie

Medals: 2

« Reply #3 - Posted 2015-01-05 17:06:49 »

thanks for the answers.

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

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 :

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.
Offline BurntPizza

« JGO Bitwise Duke »

Medals: 486
Exp: 7 years

« Reply #4 - Posted 2015-01-05 17:30:31 »

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: (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");
Pages: [1]
  ignore  |  Print  

hadezbladez (728 views)
2018-11-16 13:46:03

hadezbladez (363 views)
2018-11-16 13:41:33

hadezbladez (715 views)
2018-11-16 13:35:35

hadezbladez (179 views)
2018-11-16 13:32:03

EgonOlsen (2375 views)
2018-06-10 19:43:48

EgonOlsen (2528 views)
2018-06-10 19:43:44

EgonOlsen (1466 views)
2018-06-10 19:43:20

DesertCoockie (2132 views)
2018-05-13 18:23:11

nelsongames (1928 views)
2018-04-24 18:15:36

nelsongames (2601 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!