Here is a code snippet;
In the scene, I create the source and the extended CanvasTexture.
const theSource = Phaser.Display.Canvas.CanvasPool.create(this.textures, width, height, Phaser.CANVAS, true);
// In addition, I also tried to create source this way, to see if it makes any difference but it doesn't
/*const theSource = document.createElement('canvas');
theSource.setAttribute('width', '828');
theSource.setAttribute('height', '1792');*/
this.theCanvasTexture = new MyCanvasTexture(this.textures, 'texture_sample', theSource, width, height);
// Create a sprite based on this new texture
this.mySprite = new Phaser.GameObjects.Sprite(this, myPosX, myPosY, 'texture_sample');
this.add.existing(this.mySprite);
In the scene update loop,
this.theCanvasTexture.update(time, delta);
In MyCanvasTexture class constructor
constructor(manager, key, source, width, height) {
super(manager, key, source, width, height);
// Add this to the list, the same way addCanvas() function does
manager.list[key] = this;
manager.emit(Phaser.Textures.Events.ADD, key, this);
}
I did more testing by drawing a rectangle, in my update loop of MyCanvasTexture class
update(time, delta) {
console.log(delta);
this.clear();
this.context.fillRect(targetX, targetY, 200, 200);
this.refresh()
}
By calling this.clear(); it will break the game; but, if I comment out this.clear(); it works fine. I will see the rectangle being drawn at the target position; but, the previous drawn rectangle won’t be cleared since this.clear(); is commented out.
In addition regarding the error, right after this.clear(); is being called, my delta logged value becomes null. Both time and delta become null right after the first call of this.clear();
Then, after a few loops, everything stops with maximum stack calls.
Something with this.clear() call within extended CanvasTexture class breaks things. Not sure if it breaks the update loop? Since both delta and time returns null right after the first
this.clear(); being called.
I wonder if this is a bug?