Reducing memory use ?

Get help using Construct 2

Post » Tue Dec 17, 2013 8:34 am

Hi all,

I'm working on the Spooky Heroes project :
http://www.scirra.com/forum/topic78999.html

I didn't pay too much attention to memory use since the game is aimed at PC and images are not that big.

However, I reached a point where the game does not work anymore because of this and I can't figure out how to correct it. I posted in the bugs section and Ashley pointed out the problem came from the memory use :
http://www.scirra.com/forum/topic82826.html
I searched for a solution but I'm lacking knowledge as to how C2 actually works with images and sprites.

Let me explain :
I wish to offer many kind of heroes as well as many kind of bosses to fight against. And the game is animated which means a lot of frames and sprites. I created all animations with Flash and exported them to PNG.

When I check the folder size for the boss number 2 for example, all frames and animations included to this character, Windows indicate me a size of ~8Mo.
When I import them in C2 and place the instance on a loader layout, the memory usage indicates 130Mo used !
So I read articles and about the need for sprites to be a power of 2 (128x128) but even so, it seems a ridiculous amount of change between the 2 values !
The boss 2 is ~200x520 in size which means if it becomes power of 2, it will use 1024x1024 in memory ? Is that correct ? Does it change the size for the whole animation ? the whole sprite ? if one frame change to 1100x1100 for any reasons, will it make 2048x2048 for the whole sprite or only this frame ? Or this power 2 rule only concerns tiled backgrounds ?
When the games loads on launch, it can't loads everything because of t0o much memory use and display black squares instead of the actual sprites.

For the moment a normal character on windows indicates a 2Mo size but in C2, it indicates 15Mo. I have 13 normal characters...
Right now, the memory used on the preload page is 550Mo in total (with backgrounds and all)... Even if I optimize all of them, I will still need more of them and the size will still be a lot. I fear that I won't be able to implement everything I want for this game because the memory use on first laod will be too high.

Could you give me more information about all this stuff because I'm guessing I'm mixing up things and it's quite confusing.
How to make this work ?

Thanks !
B
10
S
2
Posts: 67
Reputation: 690

Post » Tue Dec 17, 2013 8:45 am

There is a difference between a saved image and a rendered image. Saved images are compressed to take up the least amount of space possible.

While being rendered the image is not compressed. so one 512x512 image will take up 512x512x4 = 1048576bytes of graphic memory. LittleStain2013-12-17 08:46:01
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 17, 2013 9:28 am

What is the x4 factor for ?

Also, even if I reduce my images, it seems like if a game has a lot of different sprites, the memory usage will still reach a high amount, causing the same problem I have now...
How do other platforms with big sprites usually do to reduce this problem ??

Actually during the game the memory usage is under 70Mo, it's just during the loading that it fails to load images...
Isn't there a way to prevent this problem ?? Because so far, it seems like my computer can't handle more than 400Mo memory usage during loading(displays black box instead of sprites). even if I reduce the sprite size... I'll still need many more character which will still reach this 400Mo limit...
Does that mean there is no solution ?
B
10
S
2
Posts: 67
Reputation: 690

Post » Tue Dec 17, 2013 9:47 am

I believe the 4 stands for R,G,B and Alpha.

Some simple questions to help you along:

Do you really need the sprites to be this big?
Could you work with repetition instead of using new sprites?
Can the animations be shortened without instantly looking bad?

Even large game-making-companies use techniques like repetition to reduce the amount of graphic memory used by the game. It's just one of those things gamemakers should take into account.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 17, 2013 9:53 am

This blogpost has information on wasting precious memory with graphics.

And this topic has some nice info about reducing image impact on performance.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 17, 2013 10:39 am

Ok I'm gonna check this.

In worst case, I was thinking about creating separate parts for each characters (head, arm, body, leg, foot) and animating them directly in the code with the PIN behavior.
B
10
S
2
Posts: 67
Reputation: 690

Post » Tue Dec 17, 2013 11:21 am

Another question I had about this was that only the total memory use is quite big. But actually, when the player play normally, the memory use is not that big.

Isn't there a way to make the game load everything piece by piece ? For the moment, it seems like the game loads the whole images at once and since it becomes too big, some images are lost. Can't I make the game load it more slowly ?
B
10
S
2
Posts: 67
Reputation: 690

Post » Tue Dec 17, 2013 1:43 pm

Construct 2 already manages memory efficiently: it only loads the current layout in to memory at a time (with the WebGL renderer, anyway). However if you have a single layout using tonnes of memory, it won't help you there. Construct 2's memory usage estimate in the status bar is based on the largest layout only, not the whole project.
Scirra Founder
B
403
S
238
G
89
Posts: 24,653
Reputation: 196,143

Post » Tue Dec 17, 2013 3:47 pm

Thanks for your answer Ashley &LittleStain. I've been able to diminish the memory usage thanks to that and I didn't start optimizing images yet. Also after reading the links given by LittleStain, it was already explained in those.
So sorry to have bothered you about something already answered !

Have a nice day/night !
B
10
S
2
Posts: 67
Reputation: 690


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests