Skip to content
Snippets Groups Projects
Commit cf2d2ee9 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

fix: #fe avoid texture key overlaps

parent 2395eace
No related branches found
No related tags found
No related merge requests found
...@@ -12,10 +12,11 @@ const DESCENDERS = /[AFHJPQYZÄfghjpqsyzß]/; ...@@ -12,10 +12,11 @@ const DESCENDERS = /[AFHJPQYZÄfghjpqsyzß]/;
class Clue extends Phaser.GameObjects.Sprite { class Clue extends Phaser.GameObjects.Sprite {
word: Types.Word; word: Types.Word;
scene: FightScene; scene: FightScene;
textureKey: string;
constructor(scene: FightScene, word: Types.Word) { constructor(scene: FightScene, word: Types.Word) {
// TODO: set positions // TODO: set positions
super(scene, 400, 300, word.id); super(scene, 400, 300, "__MISSING");
scene.add.existing(this); scene.add.existing(this);
this.setAlpha(0); this.setAlpha(0);
...@@ -23,12 +24,14 @@ class Clue extends Phaser.GameObjects.Sprite { ...@@ -23,12 +24,14 @@ class Clue extends Phaser.GameObjects.Sprite {
this.scene = scene; this.scene = scene;
this.word = word; this.word = word;
// TODO: we could be smarter and fully leverage caching, but meh.
this.textureKey = `${word.id}-${Date.now()}`;
this.loadTexture(); this.loadTexture();
} }
loadTexture() { loadTexture() {
// this.scene.textures.remove() // this.scene.textures.remove()
this.scene.textures.addBase64(this.word.id, this.word.image); this.scene.textures.addBase64(this.textureKey, this.word.image);
this.scene.textures.once( this.scene.textures.once(
"addtexture", "addtexture",
this.showTexture.bind(this), this.showTexture.bind(this),
...@@ -45,7 +48,7 @@ class Clue extends Phaser.GameObjects.Sprite { ...@@ -45,7 +48,7 @@ class Clue extends Phaser.GameObjects.Sprite {
} }
applyTexture() { applyTexture() {
this.setTexture(this.word.id); this.setTexture(this.textureKey);
const scale = const scale =
(this.estimateWordHeight() * BASE_HEIGHT) / (this.estimateWordHeight() * BASE_HEIGHT) /
this.texture.getSourceImage().height; this.texture.getSourceImage().height;
...@@ -68,8 +71,8 @@ class Clue extends Phaser.GameObjects.Sprite { ...@@ -68,8 +71,8 @@ class Clue extends Phaser.GameObjects.Sprite {
delete() { delete() {
this.fadeOut(() => { this.fadeOut(() => {
this.scene.textures.remove(this.texture); // TODO this.texture.destroy();
this.destroy.bind(this); this.destroy();
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment