pixijs / pixijs

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
http://pixijs.com
MIT License
43.94k stars 4.78k forks source link

Error when creating sprite with spritesheet texture #8295

Closed 0tomdev closed 2 years ago

0tomdev commented 2 years ago

I am trying to create a sprite from a texture that I loaded from a spritesheet, but I am getting this error: image

Here is where I load the spritesheet:

// main.js
Loader.shared.add("assets/tiledata.json").load(setup);

let game;

function setup() {
  const sheet = Loader.shared.resources["assets/tiledata.json"].spritesheet;
  // console.log(textures);
  console.log(sheet);
  game = new Game(sheet);
  game.start();
}

Here is where I try to create the sprite:

let s = Sprite(this.sheet.textures[tName]);

If it helps, here is a the Texture object I am passing into the Sprite constructor: image

Here is the error message again:

Uncaught TypeError: Cannot set properties of undefined (setting '_events')
    at EventEmitter (pixi.mjs:1611:16)
    at DisplayObject (pixi.mjs:7984:28)
    at Container (pixi.mjs:9156:28)
    at Sprite (pixi.mjs:31106:28)
    at Game.renderBoard (main.js:131:17)
    at TickerListener.fn (main.js:190:20)
    at TickerListener.emit (pixi.mjs:10361:22)
    at Ticker.update (pixi.mjs:10742:37)
    at Ticker._tick (pixi.mjs:10493:23)

I have searched online but I could not find this particular error. All the files I mentioned and the spritesheets are in this repository.

bigtimebuddy commented 2 years ago

This is not a loading error, it's a syntax issue:

let s = Sprite(this.sheet.textures[tName]);

Should be this

let s = new Sprite(this.sheet.textures[tName]);
// or
let s = Sprite.from(this.sheet.textures[tName]);
0tomdev commented 2 years ago

Sorry I should have realized that silly mistake. I was up late writing the code. 🙃 Thank you for the help.

bigtimebuddy commented 2 years ago

No problem, it happens. Good luck with your project.