Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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  
  using a spritesheet vs using separate sprite images?  (Read 1963 times)
0 Members and 1 Guest are viewing this topic.
Offline kynian

Junior Newbie





« Posted 2012-12-20 01:57:49 »

Hello, I've been working with lwjgl for a while, and I've had luck making characters move around and attaching sprites to them so they look like the chracter is moving (I haven't figured out how to do animation yet though) but I was having a lot of trouble with spritesheets after following some tutorials about using them. Is there a major benefit in speed or other benefit if you use a spritesheet over just separate images of the sprites (EG: player sprites, terrain sprite, etc all in different files)?
Offline ReBirth
« Reply #1 - Posted 2012-12-20 02:01:16 »

I dont remember the detail, but +1 for using spritesheet.

Offline cheatsguy

Junior Member


Medals: 3


Gamer turned Pixel Artist turned Programmer


« Reply #2 - Posted 2012-12-20 02:15:04 »

The main point is that it's neater, which can be a big deal. Other than that, I don't think it's that important, but I can't be sure.

Busy between school, work, life, games, programming and general screwing around.
If you'd like some pixel art for your game, send me a PM, i'll see what I can do.
Current project: http://elementalwarblog.wordpress.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2012-12-20 02:17:23 »

Doesn't it decrease image size? I mean having it all in one image just means expanding the length/width but 2 10x10 images take up more space than one 20x10. This is what texture packers do so I assume it's correct...
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #4 - Posted 2012-12-20 02:18:08 »

Spritesheets are better for OpenGL programming as you can just render everything in one go, instead of rebinding the texture every few vertices. It's a performance thing, but it shouldn't matter in Java2D, if that's what you're using.

Offline kynian

Junior Newbie





« Reply #5 - Posted 2012-12-20 02:22:27 »

Ah okay well I guess Ill continue trying to work with the spritesheets then, thank you all for your quick responses!
Offline davedes
« Reply #6 - Posted 2012-12-20 03:16:33 »

Since Java2D tries to use hardware acceleration under the hood, it's also wise to use sprite sheets and BufferedImage.getSubImage where possible as it may allow for better performance.

With LWJGL, sprite sheets are pretty much essential if you plan to render many sprites per frame. It should really be step 1 of optimizing any OpenGL game. Step 2 would be creating a sprite batcher, instead of using old-school glBegin/glEnd calls everywhere. If you're interested, you should check out LibGDX's sprite batcher or my own minimal sprite API here.

If you've organized your Texture wrapper well enough, then creating a sprite sheet utility should be easy as pie. See the TextureRegion source in LibGDX, for example. If your'e still struggling with basic OpenGL Texture concepts (of which texture coordinates is an essential part) then see here.

Offline kynian

Junior Newbie





« Reply #7 - Posted 2012-12-20 03:29:46 »

Since Java2D tries to use hardware acceleration under the hood, it's also wise to use sprite sheets and BufferedImage.getSubImage where possible as it may allow for better performance.

With LWJGL, sprite sheets are pretty much essential if you plan to render many sprites per frame. It should really be step 1 of optimizing any OpenGL game. Step 2 would be creating a sprite batcher, instead of using old-school glBegin/glEnd calls everywhere. If you're interested, you should check out LibGDX's sprite batcher or my own minimal sprite API here.

If you've organized your Texture wrapper well enough, then creating a sprite sheet utility should be easy as pie. See the TextureRegion source in LibGDX, for example. If your'e still struggling with basic OpenGL Texture concepts (of which texture coordinates is an essential part) then see here.

I'm still really new to LWJGL and java game design in the first place, so I'm not 100% sure what a lot of this means! xD I've been trying to follow tutorials, however there seems to be a lack of good ones out there for LWJGL. There are some limited ones from thecodinguniverse on youtube and some others, but none that go into depth on sprites. Thank you for the info however, I'll make sure to keep it in mind when I learn more.
Offline davedes
« Reply #8 - Posted 2012-12-20 03:58:08 »

I agree that there are not too many tutorials that cover LWJGL and Java-specific OpenGL programming. This is why I'm writing my own series:
https://github.com/mattdesl/lwjgl-basics/wiki

Cheers. Smiley

Offline kynian

Junior Newbie





« Reply #9 - Posted 2012-12-20 04:04:00 »

That is awesome, thank you for the link! I'll definitely be following it very closely.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #10 - Posted 2012-12-20 09:27:48 »

The libgdx texture packer handles converting separate images into a packed spritesheet, with many features like rotation and whitespace stripping. The output is packed image(s) and a text file describing the sprite positions, so it can be used without libgdx.

Offline Grunnt

JGO Wizard


Medals: 66
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #11 - Posted 2012-12-20 10:00:01 »

Is there a major benefit in speed or other benefit if you use a spritesheet over just separate images of the sprites (EG: player sprites, terrain sprite, etc all in different files)?

As far as I understand, the major benefit lies in that using a sprite sheet you can draw all sprites on the texture (that backs the sprite sheet) mixed up while still only needing to "bind" the texture only once. Since in OpenGL a texture "bind" is quite an expensive operation, this saves a lot of time compared to needing to bind a new texture for each new sprite.

I found this out for myself recently when I noticed that using one rendering approach I managed to get 12x the performance of another approach (i.e. binding a new texture for every sprite rendered). So avoiding having to many new texture binds definitely pays off.

There's some nice brief performance tips on the LibGDX wiki.

Offline Varkas
« Reply #12 - Posted 2012-12-20 14:41:03 »

Is there a major benefit in speed or other benefit if you use a spritesheet over just separate images of the sprites (EG: player sprites, terrain sprite, etc all in different files)?

In one of my former projects I used individual images. I can tell that if you want to copy like 1000 small PNGs to an USB stick, it takes like, ages. Loading is still fairly fast though.

I assume with a harddisk you don't notice this.

I then switched to zip archives containing all the small images. Makes it easier to handle, but harder to access. It allows to bundle meta data with the images though, and keeps it all together. This is a benefiot that I started to like.

It also becomes increasingly difficult to name the files, if you have them all in one folder. If you have 0000.png ... 1752.png it will become reall hard to find something.

Sprite sheets circumvent some of these problems. But if you have sprites of vastly different sizes, sheets with a fixed raster become inefficient, and you must looks for better organization of the sprites on the sheet.

I've been using both, and still couldn't make up my mind. It's not too hard to change even late in a project, though, so it wasn't a big issue for me so far.

if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline Cero
« Reply #13 - Posted 2012-12-20 16:51:19 »

Sprite sheets circumvent some of these problems. But if you have sprites of vastly different sizes, sheets with a fixed raster become inefficient, and you must looks for better organization of the sprites on the sheet.

In Libgdx's Texturepacker, it packs it just as it fits, trying not to waste space - its very effecient.
It also creates the atlas for you and everything... artists can just save every image as a single png the code of the packer will do the rest
its really the best solution

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!