Jump to content

this.game is null | cannot read property 'cache' of null


KoalaForce
 Share

Recommended Posts

I'm trying to extend the Phaser.Image class in Typescript so I can create some buttons for my UI, and remove some clutter from my main js file.

 

IE:

exitButton.anchor.setTo(0.5, 0.5);exitButton.inputEnabled = true;exitButton.visible = true;

to

var exitImage = new ButtonImage(this.game, (this.scale.width -this.yGridMargin),       this.scale.height, 'buttonSheet', 5);

When I run the game chrome and firefox return this.game is null or cannot read property cache of null.

The console seems to be point to line 35779 in the phaser.js file.

else if (typeof key === 'string' && !this.game.cache.checkImageKey(key))

ButtonImage

///<reference path = "../tsDefinitions/phaser.d.ts" />module BasicGame{			export class ButtonImage extends Phaser.Image{						constructor(game: Phaser.Game, x:number, y:number, key:any, frame: number | string){		//constructor(x: number, y:number, key: any | 'string', frame: number | string){				super(this.game, x, y, key, frame);						this.anchor.setTo(0.5, 0.5);			this.inputEnabled = true;			this.visible = true;										//game.add.existing(this);								}							}		}

Any help is much appreciated.

 

*edit for language context

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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