Jump to content

Sprite image does not load after refactoring into class


killer_manatee
 Share

Recommended Posts

Hi all, 

Brand new to phaser. When I do:

katamari = game.add.sprite(32, game.world.height - 150, 'katamari');

it works great, but when I refactor to make my code prettier/more object oriented: 

 

function Unit(game, x, y, spriteName) {
	Phaser.Sprite.call(this, game, x, y, 'units', spriteName);
	// base unit stuff goes here
}
Unit.prototype = Object.create(Phaser.Sprite.prototype);
Unit.prototype.constructor = Unit;


...


katamari = new Unit(game, 32, game.world.height - 150, 'katamari');
game.add.existing(katamari);

The sprite image fails to load. I am preloading the image correctly because it works in the first case. I have no idea why this is happening. 

Thanks

 

 

Edit: Realized issue in constructor, would delete if forum allowed

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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