@@ -10,6 +10,8 @@ var ProcessDragEvents = function (pointer, time)
1010 }
1111
1212 var i ;
13+ var c ;
14+ var overGameObject ;
1315 var gameObject ;
1416 var list ;
1517 var input ;
@@ -126,6 +128,17 @@ var ProcessDragEvents = function (pointer, time)
126128 // 4 = Pointer actively dragging the draglist and has moved
127129 if ( pointer . dragState === 4 && pointer . justMoved )
128130 {
131+ // Let's filter out currentlyOver for dropZones only
132+ var dropZones = [ ] ;
133+
134+ for ( c = 0 ; c < currentlyOver . length ; c ++ )
135+ {
136+ if ( currentlyOver [ c ] . input . dropZone )
137+ {
138+ dropZones . push ( currentlyOver [ c ] ) ;
139+ }
140+ }
141+
129142 list = this . _drag [ pointer . id ] ;
130143
131144 for ( i = 0 ; i < list . length ; i ++ )
@@ -140,12 +153,57 @@ var ProcessDragEvents = function (pointer, time)
140153 // input.dragX = pointer.x - input.localX;
141154 // input.dragY = pointer.y - input.localY;
142155
156+ // If this GO has a target then let's check it
157+ if ( input . target )
158+ {
159+ var index = dropZones . indexOf ( input . target ) ;
160+
161+ // Got a target, are we still over it?
162+ if ( index === 0 )
163+ {
164+ // We're still over it, and it's still the top of the display list, phew ...
165+ this . events . dispatch ( new InputEvent . DRAG_OVER ( pointer , gameObject , input . target ) ) ;
166+ }
167+ else if ( index > 0 )
168+ {
169+ // Still over it but it's no longer top of the display list (targets must always be at the top)
170+ this . events . dispatch ( new InputEvent . DRAG_LEAVE ( pointer , gameObject , input . target ) ) ;
171+
172+ input . target = dropZones [ 0 ] ;
173+
174+ this . events . dispatch ( new InputEvent . DRAG_ENTER ( pointer , gameObject , input . target ) ) ;
175+ }
176+ else
177+ {
178+ // Nope, we've moved on (or the target has!), leave the old target
179+ this . events . dispatch ( new InputEvent . DRAG_LEAVE ( pointer , gameObject , input . target ) ) ;
180+
181+ // Anything new to replace it?
182+ // Yup!
183+ if ( dropZones [ 0 ] )
184+ {
185+ input . target = dropZones [ 0 ] ;
186+
187+ this . events . dispatch ( new InputEvent . DRAG_ENTER ( pointer , gameObject , input . target ) ) ;
188+ }
189+ else
190+ {
191+ // Nope
192+ input . target = null ;
193+ }
194+ }
195+ }
196+ else if ( ! input . target && dropZones [ 0 ] )
197+ {
198+ input . target = dropZones [ 0 ] ;
199+
200+ this . events . dispatch ( new InputEvent . DRAG_ENTER ( pointer , gameObject , input . target ) ) ;
201+ }
202+
143203 this . events . dispatch ( new InputEvent . DRAG ( pointer , gameObject ) ) ;
144204
145205 input . onDrag ( gameObject , pointer ) ;
146206 }
147-
148- // Check drop zones
149207 }
150208
151209 // 5 = Pointer actively dragging but has been released, notify draglist
@@ -164,9 +222,9 @@ var ProcessDragEvents = function (pointer, time)
164222 input . dragY = input . localY - gameObject . displayOriginY ;
165223
166224 // Any drop zones here?
167- for ( var c = 0 ; c < currentlyOver . length ; c ++ )
225+ for ( c = 0 ; c < currentlyOver . length ; c ++ )
168226 {
169- var overGameObject = currentlyOver [ c ] ;
227+ overGameObject = currentlyOver [ c ] ;
170228
171229 if ( overGameObject . input . dropZone )
172230 {
0 commit comments