Kapsonfire Posted May 7, 2014 Share Posted May 7, 2014 Hey guys, i am trying to add a method to gameobjectcreatorPhaser.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 More sharing options...
Geoeo Posted May 7, 2014 Share Posted May 7, 2014 Why not:export class MyGameObj extends Phaser.GameObjectFactory { myCustomMethod(){ }}(Off the top of my head) Link to comment Share on other sites More sharing options...
Kapsonfire Posted May 7, 2014 Author Share Posted May 7, 2014 But the Game will use the original class and not my custom class, so i can't use this.add.myCustomMethod() on my game instance Link to comment Share on other sites More sharing options...
Geoeo Posted May 7, 2014 Share Posted May 7, 2014 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 More sharing options...
Kapsonfire Posted May 8, 2014 Author Share Posted May 8, 2014 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 More sharing options...
Recommended Posts