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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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