Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
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 9868 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 :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    public void create () {
        batch = new SpriteBatch();
        Sprite player = new Sprite(xyz); //texture and so on
    }

    public void render () {
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears the screen.
        batch.begin();
        // Drawing sprite her e.g. player.draw(batch);
        batch.end();
    }


Now in the lwjgl git ive found this :
https://github.com/mattdesl/lwjgl-basics/wiki/Sprite-Batching

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

1  
2  
... 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 »

Incorrect.

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 :
1  
2  
3  
spritexyz1.draw();
spritexyz2.draw();
spritexyz3.draw();

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 :
1  
2  
3  
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 :
1  
2  
3  
spritexyz1.draw();
spritexyz1.draw();
spritexyz1.draw();

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: 485
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: http://www.badlogicgames.com/wordpress/?p=2297 (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:

1  
Sprite gunshipSprite = atlas.createSprite("gunship1");
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
Ecumene (54 views)
2017-09-30 02:57:34

theagentd (77 views)
2017-09-26 18:23:31

cybrmynd (185 views)
2017-08-02 12:28:51

cybrmynd (183 views)
2017-08-02 12:19:43

cybrmynd (190 views)
2017-08-02 12:18:09

Sralse (200 views)
2017-07-25 17:13:48

Archive (748 views)
2017-04-27 17:45:51

buddyBro (882 views)
2017-04-05 03:38:00

CopyableCougar4 (1431 views)
2017-03-24 15:39:42

theagentd (1322 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org 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‑gaming.org
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!