Game Development Reference
In-Depth Information
Listing 13-1. Updated fakezee.json File Passes Sprite Sheet JSON Data to a Global Function
setupSpritesheet ({
"images":["img/fakezee.png"],
"frames":[
[702, 1806, 113, 50],
[817, 1787, 113, 50],
...
],
"animations":{
"diceHold":[63],
"diceTray":{
"frames":[64]
},
"die":{
"frames":[65, 66, 67, 68, 69, 70]
},
...
}
});
This JSON data is now passed into the setupSpritesheet function back in the game. In this function, you can
safely use the passed-in data parameter to create your sprite sheet. Listing 13-2 shows the updated preload and
setupSpritesheet functions for Fakezee.
Listing 13-2. Updated fakezee.json File Passes Sprite Sheet JSON Data to a Global Function
function preload() {
queue = new createjs.LoadQueue();
queue.loadManifest([
{id:"sheetData", src:"js/fakezee.json",callback: setupSpritesheet}
]);
}
function setupSpritesheet (data){
spritesheet = new createjs.SpriteSheet(data);
initGame();
}
You'll also notice that you are not declaring the sprite sheet image in the load manifest. This is because the sprite
sheet data object contains this reference and will handle the preload for you. This is the case whether you are using
JSON or JSONP.
You can continue to use PreloadJS to load your other assets for PhoneGap applications, such as images and
sounds as you normally would. However, be sure to include a separate listener for the completion of all files to init
your application. The callbacks declared for JSONP should only be used for setting up sprite sheets if other assets are
being preloaded in the queue.
when using phonegap, you may need to reference assets by using their full location path, as opposed to using
the id that you assigned it in the load manifest. the asset will be successfully loaded and available, but might not be
available via the preload queue object's getResult method. i've found this to be the case in ioS, but not in android.
Note
 
Search WWH ::




Custom Search