luiskcs89 Posted April 9, 2014 Share Posted April 9, 2014 I am using the Basic Phaser Template and I have something like the following: BasicGame.Game = function (game) { this.shadow; this.doflash; }; BasicGame.Game.prototype = { create: function () { this.shadow = this.game.add.graphics(0, 0); this.doflash = true; }, update: function () { if(doflash) { doflash = true; this.game.time.events.add(Phaser.Timer.SECOND * 1, this.flash, this); } }, flash: function () { this.shadow.clear(); this.shadow.beginFill(0xFFFFFF, this.shadowAlpha); } }; And I get the following error "Uncaught TypeError: Cannot call method 'clear' of undefined".Any ideas? Thank you Link to comment Share on other sites More sharing options...
codevinsky Posted April 9, 2014 Share Posted April 9, 2014 Graphics is completely different than canvas drawing. You'll want to do something like the following:BasicGame.Game = function (game) { this.shadow; this.doflash; }; BasicGame.Game.prototype = { create: function () { this.shadow = this.game.add.bitmapData(this.game.width, this.game.height); this.background = this.game.add.sprite(0,0, this.shadow); this.doflash = true; }, update: function () { if(doflash) { doflash = true; this.game.time.events.add(Phaser.Timer.SECOND * 1, this.flash, this); } }, flash: function () { this.shadow.clear(); this.shadow.ctx.rect(0, 0, this.game.width, this.game.height); this.shadow.ctx.fillStyle = 'white'; this.shadow.ctx.fill(); this.shadow.render(); this.shadow.refreshBuffer(); } };What this is doing is:It's using a bitmapData (this.shadow) for the texture of the newly created background sprite. Each time flash() is called, it clear's the bitmapData's context, draws a large white square, renders it, and refreshes the buffer so the sprite will use the new texture. Link to comment Share on other sites More sharing options...
XekeDeath Posted April 10, 2014 Share Posted April 10, 2014 I can't see why shadow would be undefined in the flash call from the code you posted.What line number is the error coming from? Does it match the one you have in the flash function?Have you put a break point in the flash function to see what 'this' actually is at that point? Link to comment Share on other sites More sharing options...
Recommended Posts