I have just started exploring Phaser (using v3.21.0). I came across a problem.
When I write all of my code inside a single class (extended from Phaser.Scene
), this.player.body.onWall()
is working as expected. So are other methods - like onFloor
.
this.player = this.physics.add.sprite(...) // definition of this.player
However, when I created the Player entity in a separate class (extended from Phaser.Physics.Arcade.Sprite
), this.body.onWall
appears to be undefined
.
this.body = scene.physics.add.sprite(...) // inside Player class
this.player = new Player({ scene, ... }) // inside main Scene class
What am I doing wrong?
Animations and other stuff (eg: this.body.anims.play(...)
and this.body.flipX
) are working fine.