Jump to content

Sprite image does not load after refactoring into class


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');

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. 




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

Link to comment
Share on other sites


  • Recently Browsing   0 members

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