我正在尝试制作的游戏有问题。这是我的代码(非常基本):
var canvas = document.createElement("canvas");
var gameCanvas = canvas.getContext("2d");
canvas.width = 500;
canvas.height = 500;
document.body.appendChild(canvas);
// Global variables
var game;
game.fps = 60;
game._intervalId = setInterval(game.run, 1000 / game.fps);
// Game loop
game.run = function() {
game.draw();
};
// Functions
game.draw = function() {
// Background image
var bgImage = new Image();
bgImage.src = "img/background.png";
// Player image
var playerImage = new Image();
playerImage.src = "img/player.png";
// Draw
gameCanvas.drawImage(bgImage, 0, 0);
gameCanvas.drawImage(playerImage, 10, 10);
}
// Game over
document.getElementById('end').onclick = function stop(){
clearInterval(game._intervalId);
}
// Run
window.onload = game.run();
游戏无法正常运行。我做错了什么,还是我错过了什么?这是该页面的链接:http: //dl.dropbox.com/u/33213779/Game/demo_me.html
谢谢。