jdeagle Posted July 21, 2014 Share Posted July 21, 2014 I'm using game.debug.body in my update() to debug the bounding box for sprites in my game. It draws the bounding box but doesn't clear the previous drawn box so I am left with a trail of boxes across the screen. This seems to effect all sprites.game.debug.body(this.masterSprite, 'rgba(255, 255, 0, 0.1)');I looked into the source and apparently there is a preUpdate function that is supposed to get called but it seems to only get called when game.debug.dirty === false yet only clears the canvas if dirty === true.preUpdate: function () { if (this.dirty && this.sprite) { this.context.clearRect(0, 0, this.game.width, this.game.height); this.dirty = false; } }, Is this a known issue? Is there something I need to do to force clearing the canvas for the debug? Update: Looks like manually clearing the canvas does the trick. I did the following:game.debug.context.clearRect(0, 0, this.game.width, this.game.height);game.debug.body(this.masterSprite, 'rgba(0, 255, 255, 0.5)');Having to do this manually works but phaser should do this by default. What good is it to NOT clear the previous debug graphics? Link to comment Share on other sites More sharing options...
lewster32 Posted July 21, 2014 Share Posted July 21, 2014 (edited) Debug calls need to be in the render function, not update, so they can be drawn over the top of all the scene items and cleared correctly. Seems I'm wrong (you can use debug calls anywhere, though they should really be in render) and this may be a bug in certain situations on 2.0.7. Seems I was wrong about being wrong! Edited July 22, 2014 by lewster32 Link to comment Share on other sites More sharing options...
rich Posted July 22, 2014 Share Posted July 22, 2014 Debug calls should always be in the render method, never outside of it. Link to comment Share on other sites More sharing options...
lewster32 Posted July 22, 2014 Share Posted July 22, 2014 Yeah, they should be, but they do work outside of it (at least in 2.0.6) without the above problem occurring. I guess it's an outside and unintended case though. Link to comment Share on other sites More sharing options...
rich Posted July 22, 2014 Share Posted July 22, 2014 They only work outside of it in WebGL mode. In Canvas mode it won't work at all. And it should still never be done because it nearly always renders incorrect information, because the update loop hasn't finished at the time it's called so there is still every chance for the debug data to have changed between the point of calling it and the point of rendering. Link to comment Share on other sites More sharing options...
lewster32 Posted July 22, 2014 Share Posted July 22, 2014 Ah right I see. I retract my retraction then! Link to comment Share on other sites More sharing options...
rich Posted July 22, 2014 Share Posted July 22, 2014 Link to comment Share on other sites More sharing options...
Recommended Posts