Suggestions on reducing excessive memory usage

Get help using Construct 2

Post » Mon Dec 15, 2014 10:59 am

I'm making a top down shooter which runs reasonably on a moderate spec PC but uses excessive memory. Currently 2.7GB and rising. I've read all the performance improvement articles and blog posts from Ashley but am at a loss as to how I can reduce memory usage beyond what I'm already doing.

There are a large number of animations in my project (and some large sprite sheets which are between 500kb - 4mb in size) but there are no individual sprites which are larger than 50kb (all images are PNG-24 with transparency). The total size of all spritesheets is 90mb. At its busiest, there are approximately 100-150 sprites on screen. There are some large layouts (10k square) but the number of sprites rarely exceeds 1000 in a layout. Some of these sprites are repeated, so the number of unique sprites generally does not exceed 100 in a layout.

There are no large layout images, I'm using tiled backgrounds wherever possible, I'm not generating large numbers of sprites via actions or doing anything else (as far as I know) that would consume a large amount of memory.

The project is too large to share (3000+ events) but any suggestions for reducing memory usage would be appreciated.
B
12
S
2
G
1
Posts: 23
Reputation: 886

Post » Mon Dec 15, 2014 11:20 am

Are you using the techniques described in Remember not to waste your memory? You must have either an extraordinarily large number of animation frames, or many extremely large images (2048x2048 or larger), to use such an incredible amount of memory. You will simply have to use fewer frames and lower-resolution images. 2.7 GB is so insanely high that many 32-bit devices simply won't have the address space to allocate that much memory. To reach a reasonable range of devices you're looking at needing to cut at least 80% of the memory use of your project.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Mon Dec 15, 2014 11:47 am

Ashley, yes there are a large number of animations and in some cases, frames per animation. I'm following the techniques described in your article with one exception, and I think this may be my problem. I have around 20 sprite sheets that are larger than 2048x2048 but these contain many frames of animation, (so no single images anywhere near this size). There are some animations with 50+ frames (with each frame being less than 50kb).

I assumed Construct2 would physically chop up these spritesheets when loading them in as sprite strips in the image editor. If this is not the case, would it help if I broke these large sprite sheets down into smaller sprite sheets? Or do I just have too many frames in my animations?
B
12
S
2
G
1
Posts: 23
Reputation: 886

Post » Mon Dec 15, 2014 11:49 am

optimize your pictures - 2^n x 2^n for your sprites. also remove transparent edges on your animations - use that trimming option. oh yeah, if you have a designer that made those and once you trim them your animation starts "blinking" or moving away after trimming - it happens because origin points moved. your designer is gonna have to redo the images with as much as possible little transparent space.
also - use pngoo tool to optimize pngs before insertion, and you can try after but it might cause troubles. / loss of quality is minimal.
use audio compressor to compress your files by your def. to lowest possible usable - 44khz, 16 bit. ogg format or wav which uses c2.
also use background tile instead of sprite for huge images (if they're not animated).
also use groups / rework your code 5x and shorten it as much as possible to achieve the same result. it is possible.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Mon Dec 15, 2014 11:50 am

you know that screen resolution at fullHD is 1920x1080? your sprite is 2048x2048. so think how to reduce and not lose quality = gg for your big sprites. huge saving.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Mon Dec 15, 2014 1:51 pm

is the 2.7 GB the memory said at the bottom by C2? if so, remember this represents the layouts where, from the lyout view perspective, have the most memory usage, so if you have a dump layout where you put everything, that will say a very high value I guess.

Animations with 50+ frames, I wonder, are they nessecary, if you can get by with reducing them, it can help.

also

"optimize your pictures - 2^n x 2^n for your sprites."

well no, it is (2^n -2) as C2 will add 1 pixel all around each frame. but you can check if you used the crop option of the image editor for your assets (since you have quite a lot, it may make a big difference). also not using high quality downscaling but medium (you did not mention it, so I guess it is to medium, which is the default).

could we see one of the 2048x2048 spritesheet to have a better feeling of "can this be striped down with some other techniques" (like if you have 50 frames to represent a spinning ball around a ship, it will be better to make a separate ball, that will be spinning around the ship via events).
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Mon Dec 15, 2014 2:33 pm

saiyadjin wrote:optimize your pictures - 2^n x 2^n for your sprites

That's actually the worst size: 2^n - 2 is best, since Construct 2 pads all images with a 1px border round the edge when putting them on a spritesheet.

There must be thousands of large animation frames to use up gigabytes of memory. It's just a fundamentally inefficient approach to take with your game. You should redesign the project with a whole new approach. Maybe look in to Spriter for creating smooth animations with a very limited set of images. I imagine you are trying to use frame-by-frame animations to create smooth video-like playback, but you just can't do that with frame-by-frame animations without shooting memory use through the roof.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,240

Post » Mon Dec 15, 2014 2:54 pm

2^n-2 ? funny - i have in my game 3-4 sprites with 360 frames, each is 256x256 - when i export i get 2 sheets with everything on for each sprite.
i've tried then converting it all to 250x250 - and i got like 6-7 or something even more...

so you're sayin' if i use 254x254 i would get the best results? @Ashley
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Mon Dec 15, 2014 3:04 pm

@Saiyadjin, the frames have transparent edges on the spritesheet but these are trimmed in Construct2. I can rearrange the sprites on the sheets so that so they are (2^n -2), but they will still be very large. Minimal sound in my project so the issues are all image related.

@Aphrodite, the 2.7GB is the "memory use" value in the bottom right of C2. There is a dump layout but it only contains 10% of all sprites. When looking at the memory usage of the nodewebkit executable in task manager it gets close to 2.7GB. Nodewebkit spawns two processes each taking up 1.3GB when the game gets busy. Not sure why this is (using r192).

Examples of my large spritesheets include cars and furniture (e.g. the same items in different colour schemes). So the large spritesheets are composed of mostly static frames. However, I also have spritesheets for enemy heads (which are pinned to the same body to give enemy variety). Will the whole spritesheet/all frames of animation be loaded into memory for each instance of the sprite?

@Ashley, just to clarify, there are no static frames that are larger than 1024x1024 (max size per frame 200kb), and all frame-by-frame animations are between 2 and 20 frames (max size per frame 50kb). I have looked into Spriter but it can't replicate the look of the complex animations I have hand drawn.

So my question is, if the sizes of my individual frames are unchanged, is there any reduction in memory usage if I chop up my large spritesheets into smaller sprite sheets and spread the static frames across multiple animations (in one C2 sprite or multiple C2 sprites)?
B
12
S
2
G
1
Posts: 23
Reputation: 886

Post » Mon Dec 15, 2014 4:12 pm

This is my concern too. However, I think avoiding too many large images and repeat small grafics (64x64 / 128x128) to create large enviroment is enough to make a game that runs in any phone. This a guess but would be great to know a range of memory use that would run perfectly in almost all phones in order to not abuse too much and having to redo your project design in the final process of your project.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests