Game Development Reference
In-Depth Information
the Web, we will use the index.html file and VS already should be set up to run the de-
fault.html file for our project.
Another great thing about this approach is that we can add Windows 8-specific JavaScript
files to the default.html file and ignore them in our Web-based version, which loads up from
the index.html file. This allows you to also build logic into your game's core that knows
when to load up the Windows 8-specific code or ignore it if it is running on the Web. Here is
an easy way to test for that in your code:
if (typeof(WinJS) == 'undefined')
// Execute code for none win8 playback
As you can see, if we don't have a reference to WinJS we can assume the game isn't running
on Windows 8.
Modifiying the Default JavaScript File
A new Windows 8 HTML5 project in Visual Studio makes use of a default.js file. This con-
tains the boilerplate application lifecycle support; see Chapter 2 for more information on this
and on how it works. Ideally, you want your game to start up when the WinJS app calls
onActivated(). This works fine in Windows 8 but will fail on the Web since it is only loaded
when your project is running inside of Windows 8. You may have something that looks like
this from earlier:
(function () {
"use strict";
WinJS.Binding.optimizeBindingReferences = true;
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !==
activation.ApplicationExecutionState.terminated) {
// Code to run your game for the first time
} else {
// Code to run when your game returns from suspension
}
Search WWH ::




Custom Search