0

我在 game.js 文件的顶部(来自 game.ts 编译)得到了这个定义语句:

define(["require", "exports", "GameObjects"], function(require, exports, __GameObjects__) {
var GameObjects = __GameObjects__;

$(document).ready(function () {
    var game = new Game();
    $(document).keydown(game.onKeyDown);
    $(document).keyup(game.onKeyUp);
    $(document).keyup(game.onKeyUp);
});
function collides(a, b) {

和这个错误: Uncaught TypeError: undefined is not a function

从这个页面:

    <head>
    <title>Space Demo</title>
    <link href="/stylesheets/screen.css" media="all" rel="stylesheet" type="text/css" />


    <script language="javascript" src="javascripts/require.js" type="text/javascript" data-main="ts/game.js"> </script>
    <script language="javascript" src="javascripts/jquery-1.8.2.min.js" type="text/javascript"> </script>

</head>

有任何想法吗?

编辑_ _ __ _ __ _ __ _ __ _ __ _

游戏类在game.js文件中

类游戏{

//  canvas: JQuery;

CANVAS_WIDTH: number = 400;
CANVAS_HEIGHT: number = 400;

FPS: number = 30;

enemies = [];
playerBullets: Array = new Array[40];
player: GameObjects.GameObjects.Player;


canvas: HTMLCanvasElement = <HTMLCanvasElement> document.getElementById('canvas');

context2D: CanvasRenderingContext2D;

constructor () {
    // this.canvas = canvas;

    this.context2D = this.canvas.getContext("2d");
    this.canvas.width = this.CANVAS_WIDTH;
    this.canvas.height = this.CANVAS_HEIGHT;

    this.initGame();
}
4

1 回答 1

0

您正在尝试调用某些未定义/初始化的函数。

  • Game可以从那里访问您正在构建的类吗?
  • 元素是否带有ID="canvas"-element <canvas>
  • Game类有initGame方法吗?

如果您使用 Google Chrome 打开页面,并查看开发人员控制台,您应该会看到堆栈跟踪。这应该告诉您错误来自哪里。

于 2012-12-16T03:00:16.977 回答