Hi, currently I know how to create a new texture using
this.newCanvasTexture = this.scene.textures.createCanvas('texturename', width, height);
this.newCanvasTexture.context.fillStyle = '#FF0000';
this.newCanvasTexture.context.fillRect(0,0 200, 200);
this.newCanvasTexture.refresh();
this.newSprite = new Phaser.GameObjects.Sprite(this, 0, 0, 'texturename');
this.add.existing(this.newSprite);
This works fine. But I am trying to create a class that extends Phaser.Textures.CanvasTexture
and then create a new sprite using this texture;
But I just getting an error and I am not sure how to create a class that extends the CanvasTexture
export class NewClass extends Phaser.Textures.CanvasTexture {
constructor(manager, key, source, width, height) {
super(manager, key, source, width, height);
this.context.fillStyle = '#FF0000';
this.context.fillRect(0,0 200, 200);
this.refresh();
}
then in scene;
let newTexture = new NewClass (this.textures, 'texturename', '', width, height);
let newSprite = new Phaser.GameObjects.Sprite(this, 0, 0, 'texturename');
this.add.existing(newSprite);
It just breaks in the CanvasTexture constructor.
Saying this.canvas.getContext is not a function
Not sure what variable should I pass between key and source.
Through createCanvas you just pass the key, no source. So how can create the same this as createCanvas but using this extended CanvasClass?
Thanks