Hello, I want to create a Player class in for my RPG which has all the properties and methods of sprites but also will eventually have things like an inventory, health, stats, etc.
class Player extends Phaser.Physics.Arcade.Sprite {
constructor(...args) {
super(...args);
this.inventory = [];
}
pickup(item) {
if (this.inventory.length < 5) {
this.invertory.push(item);
}
}
}
However, from what I can tell, I cannot use any of the set methods for Phaser.Physics.Arcade.Sprite objects. For example, when I try to move my player
let player = new Player(this, 800, 800, 'player');
player.setVelocityX(100);
I get this error (in chrome console)
Uncaught TypeError: Cannot read property ‘setVelocityX’ of null
at Player.setVelocityX (phaser.min.js:1)
at playGame.create (game.js:33)
I’m pretty new to javascript and phaser but I want to code following good practices. I wonder if my idea to make Player extend Sprite is not a good way to achieve the functionality I want, so would like to hear if you think there is a better approach too.