@@ -157,12 +157,11 @@ var PointerConstraint = new Class({
157157 /**
158158 * A Pointer has been pressed down onto the Scene.
159159 *
160- * If this Constraint doesn't have an active Pointer then a hit test is
161- * run against all active bodies in the world. If one is found it is bound
162- * to this constraint and the drag begins.
160+ * If this Constraint doesn't have an active Pointer then a hit test is set to
161+ * run against all active bodies in the world during the _next_ call to `update`.
162+ * If a body is found, it is bound to this constraint and the drag begins.
163163 *
164164 * @method Phaser.Physics.Matter.PointerConstraint#onDown
165- * @fires Phaser.Physics.Matter.Events#DRAG_START
166165 * @since 3.0.0
167166 *
168167 * @param {Phaser.Input.Pointer } pointer - A reference to the Pointer that was pressed.
@@ -176,9 +175,20 @@ var PointerConstraint = new Class({
176175 }
177176 } ,
178177
179- onUp : function ( )
178+ /**
179+ * A Pointer has been released from the Scene. If it was the one this constraint was using, it's cleared.
180+ *
181+ * @method Phaser.Physics.Matter.PointerConstraint#onUp
182+ * @since 3.22.0
183+ *
184+ * @param {Phaser.Input.Pointer } pointer - A reference to the Pointer that was pressed.
185+ */
186+ onUp : function ( pointer )
180187 {
181- this . pointer = null ;
188+ if ( pointer === this . pointer )
189+ {
190+ this . pointer = null ;
191+ }
182192 } ,
183193
184194 /**
@@ -187,6 +197,7 @@ var PointerConstraint = new Class({
187197 * body.
188198 *
189199 * @method Phaser.Physics.Matter.PointerConstraint#getBody
200+ * @fires Phaser.Physics.Matter.Events#DRAG_START
190201 * @since 3.16.2
191202 *
192203 * @return {boolean } `true` if a body was found and set, otherwise `false`.
@@ -196,7 +207,7 @@ var PointerConstraint = new Class({
196207 var pos = this . position ;
197208 var constraint = this . constraint ;
198209
199- pointer . camera . getWorldPoint ( pointer . x , pointer . y , pos ) ;
210+ this . camera . getWorldPoint ( pointer . x , pointer . y , pos ) ;
200211
201212 var bodies = Composite . allBodies ( this . world . localWorld ) ;
202213
@@ -246,13 +257,10 @@ var PointerConstraint = new Class({
246257
247258 if ( Vertices . contains ( part . vertices , position ) )
248259 {
249- // constraint.pointA = position;
250- constraint . pointA = { x : position . x , y : position . y } ;
251-
252- constraint . bodyB = body ;
253-
260+ constraint . pointA = position ;
254261 constraint . pointB = { x : position . x - body . position . x , y : position . y - body . position . y } ;
255262
263+ constraint . bodyB = body ;
256264 constraint . angleB = body . angle ;
257265
258266 Sleeping . set ( body , false ) ;
@@ -366,6 +374,7 @@ var PointerConstraint = new Class({
366374 this . world . off ( Events . BEFORE_UPDATE , this . update ) ;
367375
368376 this . scene . sys . input . off ( InputEvents . POINTER_DOWN , this . onDown , this ) ;
377+ this . scene . sys . input . off ( InputEvents . POINTER_UP , this . onUp , this ) ;
369378 }
370379
371380} ) ;
0 commit comments