Jump to content

Uncaught TypeError: Cannot read property 'bitmapData' of null


anndorian
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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();    })();
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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