11
2+ var BlendModes = require ( '../../renderer/BlendModes' ) ;
3+ var Circle = require ( '../../geom/circle/Circle' ) ;
4+ var CircleContains = require ( '../../geom/circle/Contains' ) ;
25var Class = require ( '../../utils/Class' ) ;
3- var GameObject = require ( '../GameObject' ) ;
46var Components = require ( '../components' ) ;
5- var BlendModes = require ( '../../renderer/BlendModes' ) ;
7+ var GameObject = require ( '../GameObject' ) ;
8+ var Rectangle = require ( '../../geom/rectangle/Rectangle' ) ;
9+ var RectangleContains = require ( '../../geom/rectangle/Contains' ) ;
10+
11+ // A Zone is a non-rendering Game Object that has a position and size.
12+ // It has no texture and never renders, but does live on the display list and
13+ // can be moved, scaled and rotated like any other Game Object.
14+ // The default origin is 0.5, the center of the Zone, the same as with Game Objects.
15+ // It's useful for linking to drop zones and input hit areas and has a couple of helper methods specifically for this.
16+ // Also useful for object overlap checks, or as a base for your own non-displaying objects.
617
718var Zone = new Class ( {
819
@@ -22,23 +33,48 @@ var Zone = new Class({
2233
2334 function Zone ( scene , x , y , width , height )
2435 {
36+ if ( width === undefined ) { width = 1 ; }
37+ if ( height === undefined ) { height = width ; }
38+
2539 GameObject . call ( this , scene , 'Zone' ) ;
2640
2741 this . setPosition ( x , y ) ;
2842 this . setSize ( width , height ) ;
29- this . setOrigin ( 0 ) ;
3043
3144 this . blendMode = BlendModes . NORMAL ;
3245 } ,
3346
47+ // Centered on the Zones x/y
48+ setCircleDropZone : function ( radius )
49+ {
50+ return this . setDropZone ( new Circle ( 0 , 0 , radius ) , CircleContains ) ;
51+ } ,
52+
53+ // Centered on the Zones x/y position
54+ setRectangleDropZone : function ( width , height )
55+ {
56+ var x = - ( width / 2 ) ;
57+ var y = - ( height / 2 ) ;
58+
59+ return this . setDropZone ( new Rectangle ( x , y , width , height ) , RectangleContains ) ;
60+ } ,
61+
62+ // Define your own shape as the drop zone
3463 setDropZone : function ( shape , callback )
3564 {
36- if ( ! this . input )
65+ if ( shape === undefined )
3766 {
38- this . setInteractive ( shape , callback ) ;
67+ this . setRectangleDropZone ( this . width , this . height ) ;
3968 }
69+ else
70+ {
71+ if ( ! this . input )
72+ {
73+ this . setInteractive ( shape , callback ) ;
74+ }
4075
41- this . input . dropZone = true ;
76+ this . input . dropZone = true ;
77+ }
4278
4379 return this ;
4480 } ,
0 commit comments