2015-09-26 79 views
0

我正在使用Visual Studio,Phaser和Typescript開發我的第一款遊戲。Typescript擴展關鍵字不工作

我不能讓我的班工作時,我使用extends關鍵字

這工作:

class Game { 

game: Phaser.Game; 

constructor() { 
    // init game 
    this.game = new Phaser.Game(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State); 
} 
} 

這不:

class Game extends Phaser.Game{ 

constructor() { 
    // init game 

    super(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State); 
} 
} 

我一直在努力整天都沒有成功地弄清楚這一點,任何人都可以點亮它嗎?

+1

「不起作用」是什麼意思?你遇到了什麼錯誤? –

+0

當我使用extends關鍵字運行遊戲時,我得到一個空白屏幕,引發的錯誤是:Uncaught ReferenceError:移相器未定義 – Johntk

回答

2

phaser.js的腳本標記需要位於腳本的腳本標記之上。

每個腳本按順序運行,您的第二個示例立即依賴Phaser對象,只要它運行即已創建。

+0

非常感謝,您是怎麼知道這是我的問題?我非常感激,這是我的一個愚蠢的錯誤。 – Johntk