Jump to content

Extending Phaser.GameObjects.Sprite Class?


Recommended Posts

Hi, I've checked a couple posts on this forum regarding extending classes in Phaser, but get confused on how it exactly works, below is the code I'm trying to implement to add stats to a sprite:

class spriteStats extends Phaser.GameObjects.Sprite {
  constructor (scene, x, y,myExtra)
      super(scene, x, y);
      this.setPosition(x, y);
  setStats(speed, jump){
    var stats = {
      "speed": speed,
      "jump": jump,
    return stats

But when I attempt to create the sprite:

var hero = this.add.spriteStats(100, 450, 'hero',0).setInteractive();

it gives me a: "Uncaught TypeError: this.add.spriteStats is not a function". I don't think I'm extending the class correctly. Please forgive me, as I'm still relatively new to JavaScript. 


Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...