2012-12-15 172 views
0

我得到這個在game.js文件的頂部(從game.ts編譯)定義聲明:的Javascript =>遺漏的類型錯誤:未定義是不是一個函數

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) { 

與此錯誤:遺漏的類型錯誤:未定義是不是一個函數

從這個頁面:

<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

有一些函數正在嘗試調用,即沒有定義/初始化。

  • Game類是從那裏訪​​問你正在構造嗎?
  • 是與ID="canvas"一個<canvas> - 元素的元素?
  • Game類是否有initGame方法?

如果您使用Google Chrome打開您的頁面並查看開發者控制檯,您應該會看到堆棧跟蹤。這應該告訴你錯誤來自哪裏。

+0

對不起,但它在game.ts文件 – Nikos

+0

看到編輯上面:) – Nikos

相關問題