mike perry Posted July 17, 2018 Share Posted July 17, 2018 How to pass the cursor object to a method that belongs to a class that inherits the Phaser.Sprite class? I have a class that inherits from Phaser.State in which I create a cursor object and pass it to the update method from another class. class Play extends Phaser.State { create() { this.physics.startSystem(Phaser.Physics.ARCADE) ... this.player = new Player({ game: this.game, x: 32, y: this.world.height - 150, asset: 'dude' }) this.game.add.existing(this.player) } update() { const cursors = this.input.keyboard.createCursorKeys() this.player.update(cursors) } } Player class - problem occurs in the if condition: class Player extends Phaser.Sprite { constructor({ game, x, y, asset }) { super(game, x, y, asset) this.game.physics.arcade.enable(this) this.body.bounce.y = 0.2 this.body.gravity.y = 300 this.body.collideWorldBounds = true this.animations.add('left', [0, 1, 2, 3], 10, true) this.animations.add('right', [5, 6, 7, 8], 10, true) } update(cursors) { this.body.velocity.x = 0 if (cursors.left.isDown) { this.body.velocity.x = -150 this.animations.play('left') } } } Error message: "TypeError t is undefined" Link to comment Share on other sites More sharing options...
mike perry Posted July 17, 2018 Author Share Posted July 17, 2018 I solved this. You can't call the update method because then you override it from the Phaser.Sprite class. Instead, just change the name to your own, e.g. move(cursors) Link to comment Share on other sites More sharing options...
Recommended Posts