Crafty.removeAssets()

public void Crafty.removeAssets(Object assets)
data

Object JSON formatted (or JSON string), with assets to remove (accepts sounds, images and sprites)

Removes assets (audio, images, sprites - and related sprite components) in order to allow the browser to free memory.

Recieves a JSON fomatted object (or JSON string) containing 'audio', 'images' and/or 'sprites' properties with assets to be deleted. Follows a similar format as Crafty.load 'data' argument. If you pass the exact same object passed to Crafty.load, that will delete everything loaded that way. For sprites, if you want to keep some specific component, just don't pass that component's name in the sprite 'map'.

Note that in order to remove the sprite components related to a given sprite, it's required to pass the 'map' property of that sprite, and although its own properties's values (the properties refer to sprite components) are not used in the removing process, omitting them will cause an error (since 'map' is an object, thus it's properties can NOT omitted - however, they can be null, or undefined). It will work as long as the 'map' objects' properties have any value. Or if you define 'map' itself as an array, like: "map": [ "car", "truck" ] instead of "map": { "car": [0,0], "truck": [0,1] }. This is examplified below ("animals.png" VS. "vehicles.png" sprites).

Example

var assetsToRemoveObj = {
    "audio": {
        "beep": ["beep.wav", "beep.mp3", "beep.ogg"],
        "boop": "boop.wav"
    },
    "images": ["badguy.bmp", "goodguy.png"],
    "sprites": {
        "animals.png": {
            "map": { "ladybug": [0,0], "lazycat": [0,1] },
        },
        "vehicles.png": {
            "map": [ "car", "truck" ]
        }
    }
}

Crafty.removeAssets(assetsToRemoveObj);

See Also