What would be the best way to load images into a slick2D game. Spritesheets or single images. If it is Spritesheets how would I go about that? I just want the fastest way to load images into a slick2D game. (As long as its not to complicated) Anyways, ya spritesheets.
It depends on your goals and your design. Both ways work.
I use both depending on the situation, all of my animations are spritesheets, and so are all the images for my maps (that use TilEd files, and that requires sprite sheets anyway).
My GUI and my “items” (inventory items) are all single images though.
Interesting thank you. Whats your loading times for SixtyGig? are you loading it on a separate thread?
Loading time at the moment is basically instant. There’s an ever-so-slight delay right as a large map loads though.
But right now everything is single threaded.
EDIT: should also take into consideration I have hardly no “content” to load since I’ve been mostly working on programming the past few weeks.
Dang I only have like 30 images in my game atm (Slick2D, no sprite sheets, pre-optimized) and it’s gotta take like 10 seconds
Well, to be fair, I am loading the game off a machine with a 256gb SSD, Intel i7, 580GTX and 16Gb of ram.
How big are these images you’re loading? My sprite sheets are absolutely huge (768x1024 each, about 10 of them). You can checkout my video in my thread if you’re curious on my load times.
Two different ways to do something: different sets of pros/cons. Evaluate your situation, and act accordingly.
Spritesheets will tend to render faster, as there is only one texture (read: image) to bind. (Look up ‘texture binding’ if you don’t get that)
How would you go about doing it? There are innumerable tutorials.
Separate images may be easier to edit, so if you are going to be making frequent changes to your GUI, etc, you might want to do that. After everything is finalized, you can then make a spritesheet out of it anyway.
It’s almost certainly something else that is causing the problem. I told you a few minutes ago in the other thread about premature optimization, now I’ll tell you how to go about proper optimization: Measure and test. Specifically, use a profiler, such as VisualVM. It will tell you what is taking so long, and then you know exactly what to fix, so you don’t waste time trying to fix other things that aren’t causing the problem. Treat the cause, not the symptoms.
Again, I direct you to the great and almighty Google for more.
Most likely an I/O problem, if the files are huge (many mb each can be considered huge) and your running a standard Sata drive then you will see the load time.
If you are loading those 30 images constantly on load, say you have a map that is 32x32 tiles and each image takes up 1 tile, that is 1024 tiles in total.
If you are loading an image from disk for each and every tile, then this will be 1024 I/O operations…that is very inefficient.
Instead you should maybe take a look at loading in all images ONCE, maybe store them as a static final field in an assets class or asset manager and then create new instances from them. This means regardless of how many tiles you have, 1024 or 3523635734626 you are only having to load the files in once from the disk.
I’d say go with single images, its easier, more flexible and faster for development.
Spritesheets although more efficient for rendering just add needless complexity during development.
You should leave optimisations until the end, if it turns out that binding too many images is a bottleneck then you can always switch to spritesheets later.
What size (in KB or pixels) are these images? It should not take that long…
I assume he only has 30 images but he is loading them from disk 100’s or 1000’s of times for every object he creates, such as a grass or stone tile.
I have 64x64 pixel images along with an image manager class that loads everything upon start up.
Make sure you only load 1 of each image, it could be that you are loading many copies of each, i.e. one for each tile (or whatever the images are), which would cause the slowdown you are seeing.
Also, consider not loading everything at start up, if it can be loaded really quick (64x64 images will be quick), then you could load only what you need for the level that is being played, etc. However do this only if loading times are still a problem, otherwise it’s only another thing to potentially get wrong.
Also, you may want to make sure the image loading is actually the source of the problem, and not e.g. the JVM that needs to load (slowly), which may take some time.