Game Development Reference
In-Depth Information
args.setPromise(WinJS.UI.processAll());
}
};
. . .
app.start();
})();
Here you can see we have two places to trigger our game. So I wrap the constructor of my
games in a startNewGame() function so I can easily call this when the page is ready to load
the game. So I would add a call to startNewGame() in my app.onactivated callback when the
game loads for the first time. This covers the Windows 8 playback. In the game's main
JavaScript file I would have something like:
if (typeof(WinJS) == 'undefined') {
startNewGame(800, 480);
}
Here you can see I test if WinJS exists before trying to start my game. If WinJS doesn't exist,
which would happen in a Web build of the game, it will automatically start the game.
I also maintain two separate HTML files for my game. One is the default.html that comes
with the Visual Studio project; the second is an index.html file that will be used to deploy to
a server. The index.html file doesn't have any reference to WinJS, so it works perfectly
without any ties to the Windows 8 environment.
There is a lot you can do with this multi-page setup, especially if you plan on deploying your
game to other platforms that require their own JS libraries, such as PhoneGap or AppMobi. It
also works great for wrapping up a Windows 8 HTML5 game into a Windows Phone app us-
ing a browser control.
Tips and Tricks
While we covered a lot in the chapter about supporting dual Web and Windows 8 develop-
ment, I thought I would highlight a few other tips I found out by using these workflows my-
self.
Search WWH ::




Custom Search