azerion / phaser-input

Adds input boxes to Phaser like CanvasInput, but also works for WebGL and Mobile, made for Phaser only.
MIT License
201 stars 64 forks source link

Using definition file #51

Closed MgSam closed 7 years ago

MgSam commented 7 years ago

Sorry for the stupid request- but could you provide an example of using the .d.ts file? I cannot get the definitions to successfully merge with phaser.comments.d.ts (from Phaser proper).

AleBles commented 7 years ago

So what I usually do, is that I start out with a simple game interface that extends the default Phaser.Game, and then I inject my custom plugins like so:

    /**
     * Add any other OG plugins here after loading them in app.ts
     * e.g. phaser-nineslice
     */
    interface IGame extends Phaser.Game {
        add: PhaserInput.InputFieldObjectFactory;
    }

Then in my State I always declare a public property game (well, actully override) and use the custom Interface as the type:

    class GameView extends Phaser.State {
        //private moreGamesMenu: Fabrique.MoreGames.Menu;
        public game: IGame;

        constructor() {
            super();
        }
}

That should make it work :)