G'day fellow C2 devs.
Due to the lack of documentation on CJS, I was curious about how CJS handles asset loading & memory on startup so I compared the results of two games of mine, Star Nomad & remade Ninja Legacy RPG Defense.
In particular I noticed something odd, Star Nomad takes ~22 seconds to load all assets on most devices and consumed ~155MB of RAM. Ninja Legacy takes ~12 seconds to load and consumes ~125MB of RAM. There is quite a significant load time, which isn't explained by Store services or what not since they both have it. It then dawn on me, all this time I was worried about optimizing image assets to keep the RAM usage low, that this load time can be explained by CJS loading & decompressing audio, all of it, on launch.
It also explains why CJS doesn't need to use preload audio to prevent first sound played lag, like XDK/Crosswalk.
For comparison sake:
Star Nomad only have ~46MB worth of sprite-sheet assets in RAM, following the power of 2 * 4 convention, ie. 64 x 64 x 4 = ~16kB RAM texture, 512 x 512 x 4 = 1MB etc. Ninja Legacy has ~80MB of sprite sheets.
The difference comes down to Star Nomad having a lot more audio tracks, ~10 minutes extra worth of audio music. This causes it to use ~ 60MB more memory minus the sprite differences.
Pretty rough analysis, but it seems 1 minute of audio music = ~6MB in ram, which is pretty huge, not just in terms of memory use, but the fact it has to decompress the audio make your game loads much longer. So for those who weren't aware and working on mobile games, I hope this is helpful.
Develop games in your browser. Powerful, performant & highly capable.
The last week I spent a lot of time with cocoonJS and memory usage. I have a really huge game which is just running on latest devices so i decided to improve memory usage.
The main problem is that all images are loaded into memory even though i don't use them on the current layout. I did some research and found a cocoonjs-only function for image objects: dispose(). Unfortunately this function isnt working properly with c2 (couldnt find out why). Currently i try to replace all images with 1px * 1px images.
The idea is to unload all images i don't need and then reload them to the memory when needed. I tried to do this with the largest images and it worked... somehow. At least the game started on weak devices and i could change between layouts. BUT somehow when it reloads the big images again, it crashes.
Maybe you have an idea how to solve this problem?
I have not tried, but what you are doing seem to go against the CJS engine. They can't do loading asset when required (people have been asking for it for years), since their acceleration engine depend on having access to everything, all the time.
I thought it was hilarious that all audio gets decompressed & loaded into memory too, which is just stupid since there's no need for it.
I replaced all huge images with small images and reloaded them after the game started and this worked. But when i dont need them I want to use the dispose() function to remove them from memory. This doesnt work. Its only possible to replace them with 1px*1px images again but somehow it still uses all memory.
How do you see your memory usage? Cause all my images are shown with 0MB