onWall (and other related methods) not working when used inside a separate class based entity

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.

Never mind. I figured it out.

I needed to use this.body.body.onWall().

You nailed it. The physics.add.sprite method returns a sprite, which has a body property: https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Factory.html#sprite__anchor

1 Like