-
Notifications
You must be signed in to change notification settings - Fork 15
Assets pipeline
hugeen edited this page Oct 19, 2012
·
15 revisions
/assets
/images
/audio
/css
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"] }
];
// 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"] });
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.
/game/assets_loader.js
// Assets to load
var assetsToLoad = assets.findByScene("level");
// Load
assetsLoader(assetsToLoad, function() {
console.log("assets are loaded");
});