@@ -66,6 +66,11 @@ game.createClass('Debug', {
6666 @private
6767 **/
6868 _frames : 0 ,
69+ /**
70+ @property {Array } _hitAreas
71+ @private
72+ **/
73+ _hitAreas : [ ] ,
6974
7075 init : function ( ) {
7176 if ( game . Debug . showInfo ) {
@@ -131,6 +136,12 @@ game.createClass('Debug', {
131136 _renderCachedSprite : function ( context ) {
132137 this . super ( context ) ;
133138 game . debug . _draws ++ ;
139+ } ,
140+
141+ _renderCanvas : function ( context ) {
142+ if ( game . scene && game . scene . stage === this ) return ;
143+ if ( game . Debug . showBounds ) game . debug . _drawBounds ( this ) ;
144+ if ( game . Debug . showHitAreas && this . hitArea ) game . debug . _hitAreas . push ( this ) ;
134145 }
135146 } ) ;
136147
@@ -168,6 +179,7 @@ game.createClass('Debug', {
168179 _renderCanvas : function ( context ) {
169180 this . super ( context ) ;
170181 game . debug . _draws += this . shapes . length ;
182+ if ( game . Debug . showBounds ) game . debug . _drawBounds ( this ) ;
171183 }
172184 } ) ;
173185
@@ -176,6 +188,8 @@ game.createClass('Debug', {
176188 this . super ( context , transform , rect , offset ) ;
177189 game . debug . _draws ++ ;
178190 if ( game . Debug . showSprites ) game . debug . _drawSprite ( this , transform , rect , offset ) ;
191+ if ( game . Debug . showBounds ) game . debug . _drawBounds ( this ) ;
192+ if ( game . Debug . showHitAreas && this . hitArea ) game . debug . _hitAreas . push ( this ) ;
179193 }
180194 } ) ;
181195
@@ -272,6 +286,25 @@ game.createClass('Debug', {
272286 context . stroke ( ) ;
273287 }
274288 } ,
289+
290+ /**
291+ @method _drawBounds
292+ @param {Container } container
293+ @private
294+ **/
295+ _drawBounds : function ( container ) {
296+ var context = game . renderer . context ;
297+ var bounds = container . _getBounds ( ) ;
298+
299+ context . globalCompositeOperation = 'source-over' ;
300+ context . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
301+ context . globalAlpha = game . Debug . boundAlpha ;
302+ context . lineWidth = game . Debug . boundLineWidth ;
303+ context . strokeStyle = game . Debug . boundColor ;
304+ context . beginPath ( ) ;
305+ context . rect ( bounds . x , bounds . y , bounds . width , bounds . height ) ;
306+ context . stroke ( ) ;
307+ } ,
275308
276309 /**
277310 @method _drawCamera
@@ -319,7 +352,7 @@ game.createClass('Debug', {
319352 @param {Container } container
320353 **/
321354 _drawHitArea : function ( container ) {
322- if ( ! container . visible || container . alpha <= 0 || ! container . renderable ) return ;
355+ if ( ! container . visible || container . alpha <= 0 || ! container . renderable ) return ;
323356
324357 var context = game . renderer . context ;
325358 var wt = container . _worldTransform ;
@@ -336,20 +369,20 @@ game.createClass('Debug', {
336369 if ( hitArea ) {
337370 var wt = container . _worldTransform ;
338371 var bounds = container . _getBounds ( ) ;
339- var tx = ( bounds . x || wt . tx ) ;
340- var ty = ( bounds . y || wt . ty ) ;
372+ var tx = typeof bounds . x === 'number' ? bounds . x : wt . tx ;
373+ var ty = typeof bounds . y === 'number' ? bounds . y : wt . ty ;
341374 var scaleX = Math . abs ( wt . a / container . _cosCache ) ;
342375 var scaleY = Math . abs ( wt . d / container . _cosCache ) ;
343- var aPercX = ( container . anchor . x / container . width ) || 0 ;
344- var aPercY = ( container . anchor . y / container . height ) || 0 ;
376+ var aPercX = ( container . anchor . x / container . width ) || 0 ;
377+ var aPercY = ( container . anchor . y / container . height ) || 0 ;
345378 var hx = tx + hitArea . x * scaleX ;
346379 var hy = ty + hitArea . y * scaleY ;
347380 hx += bounds . width * scaleX * aPercX ;
348381 hy += bounds . height * scaleY * aPercY ;
349382 if ( hitArea . radius ) {
350383 // Circle
351- var r = hitArea . radius / 2 * game . scale ;
352- context . setTransform ( 1 , 0 , 0 , 1 , hx , hy ) ;
384+ var r = hitArea . radius * game . scale ;
385+ context . setTransform ( 1 , 0 , 0 , 1 , hx - r , hy - r ) ;
353386 context . beginPath ( ) ;
354387 context . arc ( r , r , r , 0 , Math . PI * 2 ) ;
355388 context . fill ( ) ;
@@ -384,8 +417,8 @@ game.createClass('Debug', {
384417 @private
385418 **/
386419 _drawHitAreas : function ( ) {
387- for ( var i = 0 ; i < game . input . items . length ; i ++ ) {
388- var item = game . input . items [ i ] ;
420+ for ( var i = 0 ; i < this . _hitAreas . length ; i ++ ) {
421+ var item = this . _hitAreas [ i ] ;
389422 this . _drawHitArea ( item ) ;
390423 }
391424 } ,
@@ -428,9 +461,9 @@ game.createClass('Debug', {
428461
429462 context . globalCompositeOperation = 'source-over' ;
430463 context . setTransform ( wt . a , wt . b , wt . c , wt . d , x , y ) ;
431- context . globalAlpha = game . Debug . boundAlpha ;
432- context . lineWidth = game . Debug . boundLineWidth ;
433- context . strokeStyle = game . Debug . boundColor ;
464+ context . globalAlpha = game . Debug . spriteAlpha ;
465+ context . lineWidth = game . Debug . spriteLineWidth ;
466+ context . strokeStyle = game . Debug . spriteColor ;
434467 context . beginPath ( ) ;
435468 context . rect ( tx , ty , width , height ) ;
436469 context . stroke ( ) ;
@@ -442,6 +475,7 @@ game.createClass('Debug', {
442475 **/
443476 _reset : function ( ) {
444477 this . _draws = 0 ;
478+ this . _hitAreas . length = 0 ;
445479 } ,
446480
447481 /**
@@ -692,6 +726,12 @@ game.addAttributes('Debug', {
692726 @default false
693727 **/
694728 showBodies : false ,
729+ /**
730+ Draw bounds of containers and graphics.
731+ @attribute {Boolean} showBounds
732+ @default false
733+ **/
734+ showBounds : false ,
695735 /**
696736 Draw camera debug.
697737 @attribute {Boolean} showCamera
@@ -722,6 +762,24 @@ game.addAttributes('Debug', {
722762 @default false
723763 **/
724764 showSprites : false ,
765+ /**
766+ Alpha of sprites.
767+ @attribute {Number} spriteAlpha
768+ @default 0.5
769+ **/
770+ spriteAlpha : 0.5 ,
771+ /**
772+ Color of sprites.
773+ @attribute {Number} spriteColor
774+ @default #00ff00
775+ **/
776+ spriteColor : '#00ff00' ,
777+ /**
778+ Bounds line width.
779+ @attribute {Number} spriteLineWidth
780+ @default 1
781+ **/
782+ spriteLineWidth : 1 ,
725783 /**
726784 Function that is called every time the debug panel is updated.
727785 @method updatePanel
@@ -806,9 +864,10 @@ var href = document.location.href.toLowerCase();
806864if ( href . match ( / \? d e b u g / ) ) game . Debug . enabled = true ;
807865if ( href . match ( / \? d e b u g d r a w / ) ) {
808866 game . Debug . showBodies = true ;
809- game . Debug . showSprites = true ;
867+ game . Debug . showBounds = true ;
810868 game . Debug . showCamera = true ;
811869 game . Debug . showHitAreas = true ;
870+ game . Debug . showSprites = true ;
812871}
813872if ( href . match ( / \? d e b u g t o u c h / ) ) {
814873 game . Debug . fakeTouch = true ;
0 commit comments