Jump to content

[TypeScript] Extend GameObjectCreator


Kapsonfire
 Share

Recommended Posts

Hey guys, i am trying to add a method to gameobjectcreator

Phaser.GameObjectFactory.prototype.myCustomMethod = function () { }

But this doesnt work, cause the compilers complains that Phaser hasnt a member with that name. Is there a way to hack around? I know that it would work in JS but cant get it working on TypeScript without changing the Phaser.d.ts

Link to comment
Share on other sites

that does make it harder. You're right.

 

I personally would shy away from changing classes given by the framework.

Maybe if you could give some context to the problem, 
we could figure out a better way to solve it

Link to comment
Share on other sites

I did already a workaround with static methods.

module Phaser.Custom {    export class BlinkText extends Phaser.Text {        blinkDisplayTime: number = 1000; //displayTime in ms        blinkInvisibleTime: number = 1000; //invisibleTime in ms        blinkTimeElapsed: number = 0;        update() {            super.update();            this.blinkTimeElapsed += this.game.time.elapsed;            var _modulo = this.blinkTimeElapsed % (this.blinkDisplayTime + this.blinkInvisibleTime);             this.visible = _modulo < this.blinkDisplayTime ? true : false;        }        static addToState(state: Phaser.State, x: number, y: number, text: string, style: any) {            var fpsText = new Phaser.Custom.BlinkText(state.game, x, y, text, style);            state.add.existing(fpsText);            return fpsText;        }        static addToGame(game: Phaser.Game, x: number, y:number, text: string, style: any){            var fpsText = new Phaser.Custom.BlinkText(game, x, y, text,style);            game.add.existing(fpsText);            return fpsText;        }          }} 

I think code is selfexplaining. Goal was to add a custom class with the GameObjectFactory

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...