Game Development Reference
In-Depth Information
Figure 13-4. Fakzee game elements, adjusted for mobile applications
The background image and canvas sizes were changed accordingly to fit the height of device screens in portrait
mode. Some code was also altered to move the game elements to better fit in the new screen format. The game logic
and application code has remained the same.
Preloading JSONP for PhoneGap
As mentioned earlier, there are currently some show-stopping conflicts between PhoneGap and PreloadJS. This can
cause issues in your application, primarily when it comes to loading data text files. In the case of Fakezee, PreloadJS
is being used to load and parse a JSON data file so it can be used in the application. This will not properly work in the
PhoneGap environment because the two use different approaches to loading data.
PhoneGap requires JSONP to be used when loading JSON data. In order to get JSONP to properly work with
PreloadJS, you must define a callback in the object you are building for the manifest.
{id:"sheetData", src:"js/fakezee.json", callback: setupSpritesheet }
With JSONP, the file is loaded in as JavaScript and auto exectutes. In your fakezee.json file, simply wrap a
function call around your sprite sheet JSON data. Now this function will fire, which is the same method declared in
the manifest object, and will pass along the JSON as it's first parameter. Listing 13-1 demonstrates this function call in
fakezee.json .
 
Search WWH ::




Custom Search