我在game.js文件的顶部得到了这个define语句(来自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) {
并且此错误:未捕获TypeError:undefined不是函数
来自此页面:
<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>
任何想法?
edit_的 _ __ _ __ _ __ _ __ _ __ _
游戏类位于thegame.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();
}
答案 0 :(得分:0)
您尝试调用的某些功能尚未定义/初始化。
Game
课程吗?ID="canvas"
是<canvas>
- 元素吗?Game
类是否有initGame
方法?如果您使用谷歌浏览器打开页面,并查看开发人员控制台,您应该看到堆栈跟踪。这应该告诉你错误的来源。