I have the following component:
import { Behaviour, Image, serializable } from "@needle-tools/engine"
import { Texture } from "three";
export class MessageHandler extends Behaviour {
@serializable(Image)
target?: Image;
@serializable(Texture)
textures?: Texture[];
@serializable()
intervalSeconds: number = 1;
private index: number = 0;
//awake() or start() produce the same result
awake() {
console.log("Awake!");
setInterval(() => {
this.target!.image = this.textures![this.index];
this.target!.image.needsUpdate = true;
this.index++;
if (this.index >= this.textures!.length)
this.index = 0;
}, this.intervalSeconds * 1000);
}
//The update approach does not change the result
// private timer: number = 0;
// update(): void {
// console.log("Update!");
// this.timer += this.context.time.deltaTime;
// console.log(this.timer);
// if (this.timer >= (this.intervalSeconds)) {
// console.log("Time up!");
// this.target!.image = this.textures![this.index];
// this.target!.image.needsUpdate = true;
// this.index++;
// if (this.index >= this.textures!.length)
// this.index = 0;
// this.timer = 0;
// }
// }
}
The idea behind is to periodically update the texture of the image cycling through a list of textures. However, right now I noticed that the update of the texture only happens when i put the mouse on top of any UI element. I tried using the same on the update function and inside start(), awake() but no changes.
Is there any way of forcing that update?
by user 368204675922657280