rcolinray / generator-phaser-typescript

A Yeoman generator for HTML5 games that use TypeScript and Phaser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to reference a generated Prefab in a state

danbolt opened this issue · comments

Hi there!

Using the generator, I generated a Prefab called Player. It placed it really nicely into its own prefab folder.

I want to reference this prefab in the Main state, so when I wrote

/// <reference path="../Prefab/Player.ts" />

module Game.State
{
  export class Main extends Phaser.State
  {
    create()
    {
      this.stage.backgroundColor = 0x000000;

      var player1 = new Player(this.game, 10, 10);
    }
  }
}

Grunt gives me a build error saying:

Running "typescript:app" (typescript) task
>> /.../app/scripts/State/Main.ts(11,25):
>> error TS2095: Could not find symbol 'Player'.
Warning: Task "typescript:app" failed. Use --force to continue.

Perhaps I'm missing something? Writing this down in case anyone gets the same error.

Looks like I forgot add export to the class definition for the Prefab. Thanks for reporting the issue.

Thanks! I appreciate the support. 👍

Just a heads up in case anyone is browsing the old issues.
This won't work anymore, you need to call Prefab.Player, not Player if you reference module like that.

/// <reference path="../Prefab/Player.ts" />

module Game.State
{
  export class Main extends Phaser.State
  {
    create()
    {
      this.stage.backgroundColor = 0x000000;

      var player1 = new Prefab.Player(this.game, 10, 10);
    }
  }
}