Skip to content

Commit 5a9b509

Browse files
committed
ArraySet.removeAll allows you to remove all members of an ArraySet and optionally call destroy on them as well.
GameObject.input.dragStartPoint now stores the coordinates the object was at when the drag started. This value is populated when the drag starts. It can be used to return an object to its pre-drag position, for example if it was dropped in an invalid place in-game.
1 parent 23d31ff commit 5a9b509

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ We've also removed functions and properties from Pixi classes that Phaser doesn'
127127
* Sprite.left, Sprite.right, Sprite.top, Sprite.bottom are new properties that contain the totals of the Sprite position and dimensions, adjusted for the anchor.
128128
* Sprite.offsetX and Sprite.offsetY contain the offsets from the Sprite.x/y coordinates to the top-left of the Sprite, taking anchor into consideration.
129129
* Emitter.flow now works in a slightly different (and more useful!) way. You can now specify a `quantity` and a `total`. The `quantity` controls how many particles are emitted every time the flow frequency is met. The `total` controls how many particles will be emitted in total. You can set `total` to be -1 and it will carry on emitting at the given frequency forever (also fixes #1598 thanks @brianbunch)
130+
* ArraySet.removeAll allows you to remove all members of an ArraySet and optionally call `destroy` on them as well.
131+
* GameObject.input.dragStartPoint now stores the coordinates the object was at when the drag started. This value is populated when the drag starts. It can be used to return an object to its pre-drag position, for example if it was dropped in an invalid place in-game.
130132

131133
### Updates
132134

src/input/InputHandler.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ Phaser.InputHandler = function (sprite) {
187187
*/
188188
this.dragFromCenter = false;
189189

190+
/**
191+
* @property {Phaser.Point} dragStartPoint - The Point from which the most recent drag started from. Useful if you need to return an object to its starting position.
192+
*/
193+
this.dragStartPoint = new Phaser.Point();
194+
190195
/**
191196
* @property {Phaser.Point} _dragPoint - Internal cache var.
192197
* @private
@@ -1296,6 +1301,7 @@ Phaser.InputHandler.prototype = {
12961301
this.sprite.bringToTop();
12971302
}
12981303

1304+
this.dragStartPoint.set(x, y);
12991305
this.sprite.events.onDragStart$dispatch(this.sprite, pointer, x, y);
13001306

13011307
},

src/utils/ArraySet.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,36 @@ Phaser.ArraySet.prototype = {
180180
}
181181
}
182182

183+
},
184+
185+
/**
186+
* Removes every member from this ArraySet and optionally destroys it.
187+
*
188+
* @method Phaser.ArraySet#removeAll
189+
* @param {boolean} [destroy=false] - Call `destroy` on each member as it's removed from this set.
190+
*/
191+
removeAll: function (destroy) {
192+
193+
if (typeof destroy === 'undefined') { destroy = false; }
194+
195+
var i = this.list.length;
196+
197+
while (i--)
198+
{
199+
if (this.list[i])
200+
{
201+
var item = this.remove(this.list[i]);
202+
203+
if (destroy)
204+
{
205+
item.destroy();
206+
}
207+
}
208+
}
209+
210+
this.position = 0;
211+
this.list = [];
212+
183213
}
184214

185215
};

0 commit comments

Comments
 (0)