Error trying to load a sprite into my scene

I’ve been trying to follow a youtube tutorial and I’m trying to add a sprite into my scene but I’m coming across an error I haven’t been able to find out much about. The error message is…

phaser.js?d4ef:192479 Uncaught TypeError: this.resetCropObject is not a function
    at Object.MatterSprite [as Sprite]

Searching for the error I came across one github issue, https://github.com/photonstorm/phaser/issues/5211, not sure if it’s related or not. I have tried pulling in the version from the master branch but the problem still persists.

My code is below.

import { Scene } from 'phaser'
import store from '../../store/index';

export default class MainScene extends Scene {
  constructor () {
    super({ key: 'MainScene' });
  }

  preload() {
      this.load.atlas('player', '/assets/sprites/player.png', '/assets/sprites/player_atlas.json');
  }

  create () {
    this.player = Phaser.Physics.Matter.Sprite(this.matter.world, 0, 0, 'player', 'idle_behind_1');

    this.add.existing(this.player);
  }
}

https://eager-goldberg-2913b2.netlify.app/

1 Like

What version are you using?

The latest stable tagged version, 3.24.1. I also tried the latest beta and the master branch directly. Same thing on them all.

this.player = this.matter.add.sprite(0, 0, 'player', 'idle_behind_1');
2 Likes

Thank you @samme, that was it. I must have been following along with an old version or something.

By the way, the original mistake in your code was calling Phaser.Physics.Matter.Sprite as a function. It’s meant to be instantiated - new Phaser.Physics.Matter.Sprite(...). The tutorial is wrong if it told you to use a function call.

Still, samme’s suggestion is the best solution. this.matter.add.sprite is equivalent to constructing a sprite and calling add.existing on it.

2 Likes

You prompted me to go back and take a closer look, and yep, they’re instantiating it in the tutorial, I just missed it. Oops.