Jump to content

Unloading assets to clear memory?


Ninjadoodle
 Share

Recommended Posts

Hi guys

 

I'm cleaning up my game for devices ( using Cocoon JS ) and loading my levels dynamically ( level by level ), not to overload the device.

 

This works nicely until about 2/3 of the game, when I get a 'Memory Warning' on both Android and iOS.

 

I'm assuming that the graphics loaded each level are stacking up, and the phone is only releasing what it needs when the memory gets full.

 

Is there a way I can 'Unload' the assets, in the same way I load them, when they are no longer needed?

 

I'm worried this might cause crashes on weaker devices.

 

Thank you in advance for any help!

Link to comment
Share on other sites

Ok just pushed some changes, the syntax is now this:

game.removeAsset('logo.png'); // Remove sprite from memorygame.removeAsset('sprites.json'); // Remove sprite sheet from memorygame.removeAssets(); // Remove all assets from memorygame.system.setScene('Game', true); // Change scene and remove all assets from memory
Link to comment
Share on other sites

Hi @enpu

 

I've just been testing this and there is one problem ...

 

If you removeAsset, the engine doesn't seem to let you add the same asset at a later stage.

 

For example if I load a levels assets, then unload them after leaving, then try to load the assets again upon entering, I get an error :(

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...