0
我正在嘗試爲Windows 8應用程序使用Canvas和Javascript製作一個基本的應用程序。在編譯在Visual Studio 2012的代碼爲Windows 8應用程序我得到以下信息Javascript運行時錯誤:應用程序undefined
0x800a1391 - JavaScript runtime error: 'app' is undefined
我做了錯誤的,什麼樣的代碼做我用它來解決這個問題?
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Untitled</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
<!-- references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
<!-- CreateJS -->
<script src="js/createJS/easeljs-0.5.0.min.js" type="text/javascript"></script>
<script src="js/createJS/preloadjs-0.2.0.min.js" type="text/javascript"></script>
</head>
<body>
<canvas id="gameCanvas"></canvas>
</body>
</html>
JS
var canvas, content, stage;
var bgimage, b1Image, p2Image, ammoImage, p1Lives, p2Lives, title, endGameImage;
var bgbitmap, p1bitmap, p2bitmap, ammoBitmap;
var preload;
// Scale Factor
var SCALE_X = window.innerWidth/800;
var SCALE_Y = window.innerHeight/480;
var MARGIN = 25;
var GROUND_Y = 390 * SCALE_Y;
function initialize() {
canvas = document.getElementById("gameCanvas");
canvas.width = window.innWidth
canvas.height = window.innerHeight;
context = canvas.getContext("2d");
function prepareGame() {
bgimage = preload.getResult("screenImage").result;
bgbitmap = new Bitmap(bgimage);
bgbitmap.scaleX = SCALE_X
bgbitmap.scaleY = SCALE_Y
stage.addChild(bgBitmap);
stage.update();
}
//PreloadJS
preload = new PreloadJS();
preload.onComplete = prepareGame;
var manifest = [
{ id: "screenImage", src: "images/Backgrounds/gameplay_screen.png" },
{ id: "redImage", src: "images/Catapults/Red/redIdle/redIdle.png" },
{ id: "blueImage", src: "images/Catapluts/Blue/blueIdle/blueIdle.png" },
{ id: "ammoImage", src: "images/Ammo/rock_ammo.png" },
{ id: "winImage", src: "images/Backgrounds/victory.png" },
{ id: "loseImage", src: "images/Backgrounds/defeat.png" },
{ id: "blueFire", src: "images/Catapults/Blue/blueFire/blueCatapult_fire.png" },
{ id: "redFire", src: "images/catapults/Red/redFire/redCatapult_fire.png" }
];
preload.loadManifest(manifest);
stage = new Stage(canvas);
}
function gameLoop() {
update();
draw();
}
function update() {
}
function draw() {
}
app.oncheckpoint = function (args) {
document.addEventListener("DOMContentLoaded", initialize, false);
app.start();
};
同樣在我使用CreateJS如果這意味着什麼