anndorian Posted July 12, 2014 Share Posted July 12, 2014 Hi, I have the following code: (function(){ var game var Test = function (game) { var bd = game.make.bitmapData(50, 50); bd.fill(255, 0, 0); Phaser.Sprite.call(this, game, 0, 0, bd); }; Test .prototype = Object.create(Phaser.Sprite.prototype); Test .prototype.constructor = Test ; function init() { game = new Phaser.Game(640, 480, Phaser.AUTO, 'gameid'); var test = new Test(game); } init(); })();Once i'm creating the 'test' variable I get this error Uncaught TypeError: Cannot read property 'bitmapData' of null Any thoughts on this one? Thank you for your time. indie-jones 1 Link to comment Share on other sites More sharing options...
lewster32 Posted July 12, 2014 Share Posted July 12, 2014 Phaser has not yet had time to set up its subsystems because you're not passing it any states. Try this: (function(){ var game var Test = function (game) { var bd = game.make.bitmapData(50, 50); bd.fill(255, 0, 0); Phaser.Sprite.call(this, game, 0, 0, bd); }; Test .prototype = Object.create(Phaser.Sprite.prototype); Test .prototype.constructor = Test ; function init() { // ensure at least a 'create' state is passed game = new Phaser.Game(640, 480, Phaser.AUTO, 'gameid', {create: create}); } // our create state function create() { // we can now be sure all of Phaser's subsystems are enabled, so create it now var test = new Test(game); // add it to the game to make sure it's there (it is - yay!) game.add.existing(test); } init(); })(); clark 1 Link to comment Share on other sites More sharing options...
Recommended Posts