I have just started with Typescript, using Visual Studio 2015, and can't find a way to use classes in separate files.
In a single file, there is no problem:
module someModule {
export class TitleScreenState extends Phaser.State {
game: Phaser.Game;
constructor() {
super();
}
//some code here
}
class GameRunningState extends Phaser.State {
constructor() {
super();
//some code here
}
class SimpleGame {
game: Phaser.Game;
//some code here
}
}
}
window.onload = () => {
var game = new MyGame.Game();
};
However, when the classes are moved into their own files, they show no errors, but at runtime I get:
0x800a1391 - JavaScript runtime error: 'MyGame' is undefined
// app.ts
/// <reference path='Game.ts'/>
/// <reference path='StateTitleScreen.ts'/>
/// <reference path='StateGameRunning.ts'/>
window.onload = () => {
var game = new MyGame.Game();
};
//----------------------------------------
// Game.s
module MyGame {
export class Game {
// some code here
}
//-----------------------------------------
// StateTitleScreen.ts
module MyGame {
export class StateTitleScreen {
// some code here
}
//-----------------------------------------
// StateGameRunning.ts
module MyGame {
export class StateGameRunning {
// some code here
}