optimization loading and reloading many images/sprites

Hello,

I’m almost done with a game and I have some questions to optimized it, I would like to be adviser before starting a changement of my preloading game/managers.

What I’m doing for now is preloading all the images/sprites I will need for my game in the composer create function, putting them not visible and not bodyActive and use a manager to putting them active when needed.

But the thing is I have 1500 images/sprites at once out of screen when I preload them (I don’t know if it’s a lot)

I expose my issue :

  1. I need to change completely the decor during the game, but removing everything and reloading the whole with new data make a big freeze during this step (not enough smooth, looks logic lol).

What I thought was to use a sprite sheet on everything even for some stuff where I use newImageRect, and swap the image to the correct decor when needed.

The fact is that some elements will be use only later on the game and have no equivalent to be swap and some other elements use at the begining are no longer needed later on the game, so loading all the decor before should use more texture memory and increase my number of sprite(sheet.png and display object) for nothing, at least if the player don’t go far enough.

I was wondering if there is another way to switch to a new decor smoothly and efficiently ? otherwise I would optimzed my game on this way

  1. excepted the changement of decor everything work fine even with 1500 images loaded at once ( checked with benchmark, using 5-20% of cpu)  but when my battery level gone low the performance of my game are discreased a lot.

I suspect the huge amount of images loaded (on and off screen) to be the cause of this problem (I think about use texture manager and use display library to display them to avoid to preload that much of images/sprites but sprite sheet are not allowed for it …), is this already happened to someone ?

I’m open to all discussions/tutorials/advertises/experiences it could help myself, I can be more precise if needed.

If you have 1500 individual images I imagine they are all reasonably small and mostly used to comprise the elements of a single scene. This is the perfect situation for using a sprite sheet for a given level, scene, character or whatever. It will conserve memory and boost performance. You don’t need to put every image for your game level into the same sheet, but use common sense to gather stuff into logical sheets to keep them simple.

It might seem difficult to let go of the idea that you need all your game’s images loaded all the time - and in fact, if the images are nice and small, you might be able to. I’m sure there are plenty of games out there with 1000s of images loaded at once. But good memory management would imply that reducing that number is better.

Try loading only the images for one theme of your level. When you need to change the look and feel (L&F) of the level, you could put an animation on screen which blocks user interaction, pauses the game and shows that you are loading the images while dumping the old ones (replacing their variables in memory.) It might seem like a slow process, but if you’re reducing the number of images down to a few spritesheets you might only be loading a small number of them and then you just refresh the level objects from the new sheet object.

In my code I try to render as many game visuals as I can with code, rather than images, which keeps the binary incredibly small. But that’s me and I enjoy that kind of masochism.

Try doing what I do… load assets to textures (in memory) on load but I don’t draw them if they are not on screen.  i have an enterFrame() that works out if the assets are in view/out of view and draw or remove them as appropriate.

This drastically reduces the load time but this obviously increases the code logic.  the net result is lower memory load and faster rendering.

Try splitting your Atlases into must be loaded v may be loaded.

Basically partition your rendering logic.  If I was to put all my assets into Atlases it would need 20 x 4096 x 4096px which = crazy memory!

@horacebury: I’ve managed my game and putting everything into few sprite sheet, preloading sprite object and then when I need to load the object I set the desired frame.

Now the changement of decor  is smooth, I reduce by the way the number of image loading at once to 600, I can do better I think but for now it’s fine

I would like know, is it setting a small sequence with few frames on a sprite object is improving memory than set a sequence with the whole frame ? (I have made sheet within 35 frames), because I could make a sequence for each different decor if it’s memory improvement

@sphere Game Studio: I have not that much assets lol revisiting them I success to have a good deal I’m still working on it but for the memory it look good, because what I’ve read a time ago, sprite sheet texture are not supported so I should have to make the animation by myself …

I’m certainly going to use texture for my backgrounds, to draw the good image when needed

But the thing is as horacebury say I’m maybe going to split my background image into small asset (ground, tree, leaf, moutain etc…)  and then organized them with a manager, for not having many background image or a reapeating background all the way

If you have 1500 individual images I imagine they are all reasonably small and mostly used to comprise the elements of a single scene. This is the perfect situation for using a sprite sheet for a given level, scene, character or whatever. It will conserve memory and boost performance. You don’t need to put every image for your game level into the same sheet, but use common sense to gather stuff into logical sheets to keep them simple.

It might seem difficult to let go of the idea that you need all your game’s images loaded all the time - and in fact, if the images are nice and small, you might be able to. I’m sure there are plenty of games out there with 1000s of images loaded at once. But good memory management would imply that reducing that number is better.

Try loading only the images for one theme of your level. When you need to change the look and feel (L&F) of the level, you could put an animation on screen which blocks user interaction, pauses the game and shows that you are loading the images while dumping the old ones (replacing their variables in memory.) It might seem like a slow process, but if you’re reducing the number of images down to a few spritesheets you might only be loading a small number of them and then you just refresh the level objects from the new sheet object.

In my code I try to render as many game visuals as I can with code, rather than images, which keeps the binary incredibly small. But that’s me and I enjoy that kind of masochism.

Try doing what I do… load assets to textures (in memory) on load but I don’t draw them if they are not on screen.  i have an enterFrame() that works out if the assets are in view/out of view and draw or remove them as appropriate.

This drastically reduces the load time but this obviously increases the code logic.  the net result is lower memory load and faster rendering.

Try splitting your Atlases into must be loaded v may be loaded.

Basically partition your rendering logic.  If I was to put all my assets into Atlases it would need 20 x 4096 x 4096px which = crazy memory!

@horacebury: I’ve managed my game and putting everything into few sprite sheet, preloading sprite object and then when I need to load the object I set the desired frame.

Now the changement of decor  is smooth, I reduce by the way the number of image loading at once to 600, I can do better I think but for now it’s fine

I would like know, is it setting a small sequence with few frames on a sprite object is improving memory than set a sequence with the whole frame ? (I have made sheet within 35 frames), because I could make a sequence for each different decor if it’s memory improvement

@sphere Game Studio: I have not that much assets lol revisiting them I success to have a good deal I’m still working on it but for the memory it look good, because what I’ve read a time ago, sprite sheet texture are not supported so I should have to make the animation by myself …

I’m certainly going to use texture for my backgrounds, to draw the good image when needed

But the thing is as horacebury say I’m maybe going to split my background image into small asset (ground, tree, leaf, moutain etc…)  and then organized them with a manager, for not having many background image or a reapeating background all the way