I am trying to pass my callback collectStar
to the overlap
method. However, it is getting passed as undefined
, and I don't know why.
If I pass () => {}
instead of the reference it works; this however isn't what I want because it isn't reusable.
Here is the basics of what I am doing:
class SimpleGame {
// Init the game
constructor(width: number, height: number) {
this.game = new Game(width, height, Phaser.AUTO, 'content', { preload: this.preload, create: this.create, update: this.update })
}
// Callback
collectStar(player: Rope, star: Rope) {
star.kill()
}
// The update loop
update(){
this.game.physics.arcade.overlap(
this.player,
this.stars,
this.collectStar,
undefined,
this
);
}
}
document.addEventListener('DOMContentLoaded', e => {
new SimpleGame(800, 600)
})
Why is this getting passed as undefined?