DanielMontilla Posted December 22, 2019 Share Posted December 22, 2019 Trying to spawn target periodically using .time.addEvent. But the callback function won't spawn the sprite. Console spits out TypeError: this.add is undefined. I'm fairly new to JavaScript sorry. (I've placed the sprite outside of the spawnTarget function and it works fine!) create() { let targetSpawnInterval = 350; function spawnTarget () { this.add.sprite(Phaser.Math.Between(0, 600), Phaser.Math.Between(0, 800), 'target'); }; this.time.addEvent({ delay: targetSpawnInterval, callback: spawnTarget, loop: true }); } Link to comment Share on other sites More sharing options...
Recommended Posts