Jump to content

Error: Uncaught TypeError: Cannot read property 'width' of undefined for setPreloadSprite


predator
 Share

Recommended Posts

When I am running the following code, my browser (chrome) returns an error when I try to run setPreloadSprite. The error is 

Uncaught TypeError: Cannot read property 'width' of undefined

When I am trying to run 

    this.preloadbg = this.add.sprite(this.game.world.centerX, this.game.world.centerY, 'loadbg');
    console.log('reached');
    this.preloadbg.anchor.setTo(0.5);
    this.preloadbg.scale.setTo(10);
    this.preloadbar = this.add.sprite(this.game.world.centerX, this.game.world.centerY, 'loadbar');
    this.preloadbar.anchor.setTo(0.5);
    this.preloadbar.scale.setTo(10);
    this.load.setPreloadSprite(this.preloadBar);

Why is this error coming? When I look at the error text, it says it is coming from the 'phaser.js' file. Is there really that big of a bug?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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