I am adding a sprite to my game like this:
enemy = this.physics.add.sprite(280, 32, 'enemy');
Now I'd like to add it from inside a function like this:
spawn(this.enemy);
function spawn(enemy) {
enemy = this.physics.add.sprite(280, 32, 'enemy');
}
It doesn't work, I get the following error:
TypeError: this.physics is undefined
What do I have to write instead of this.physics
?