Jump to content

Can't create sprite within own fucntion


Recommended Posts

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');
            delay: targetSpawnInterval,
            callback: spawnTarget,
            loop: true


Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...