Skip to content
This repository

Assets pipeline 

hugeen edited this page · 15 revisions
/assets
    /images
    /audio
    /css

How to add assets to the collection ?

Adding them to the assets.js file

This file (/game/assets.js) is called automatically to feed the assets backbone collection

return [
    { type: "sprites", name: "wolf", size: 135, scenes: ["level"] },
    { type: "sprites", name: "pig", size: 115, scenes: ["level"] }
];

Adding them on the fly

// Add Image to the assets collection
assets.add({ type: "images", name: "background", scenes: ["level"] });
// Add Audio to the assets collection
assets.add({ type: "audio", name: "music", scenes: ["level"] });
// Add Sprite to the assets collection
assets.add({ type: "sprites", name: "wolf", size: 135, scenes: ["level"] });

The Sprites case

If your asset is a sprite, a few options will be added by default:

var defaults = {
    size: 32,
    padding: {
        x: 0,
        y: 0
    },
    maps: [{
        name: this.get("name"),
        coords: { x: 0, y: 0, w: 1, h: 1 }
    }]
};

For more information on these options, please refer to the crafty documentation.

Assets loading

/game/assets_loader.js

// Assets to load
var assetsToLoad = assets.findByScene("level");

// Load
assetsLoader(assetsToLoad, function() {
    console.log("assets are loaded");
});
Something went wrong with that request. Please try again.