Skip to content

Commit 1956d35

Browse files
committed
InputHandler.dragStopBlocksInputUp is a boolean that allows you to control what happens with the input events. If false (the default) then both the onInputUp and onDragStop events will get dispatched when a Sprite stops being dragged. If true then only the onDragStop event is dispatched, and the onInputUp is skipped.
1 parent 913936f commit 1956d35

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
350350
* InputHandler.dragTimeThreshold gives you more fine control over when a Sprite Drag event will start. It allows you to specify a time, in ms that the pointer must have been held down for, before the drag will begin.
351351
* InputHandler.downPoint is a new Point object that contains the coordinates of the Pointer when it was first pressed down on the Sprite.
352352
* There are two new Phaser consts available, for help with orientation of games or Game Objects. They are `Phaser.HORIZONTAL`, `Phaser.VERTICAL`, `Phaser.LANDSCAPE` and `Phaser.PORTRAIT`.
353+
* InputHandler.dragStopBlocksInputUp is a boolean that allows you to control what happens with the input events. If `false` (the default) then both the `onInputUp` and `onDragStop` events will get dispatched when a Sprite stops being dragged. If `true` then only the `onDragStop` event is dispatched, and the `onInputUp` is skipped.
353354

354355
### Updates
355356

src/input/InputHandler.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ Phaser.InputHandler = function (sprite) {
181181
*/
182182
this.dragFromCenter = false;
183183

184+
/**
185+
* @property {boolean} dragStopBlocksInputUp - If enabled, when the Sprite stops being dragged, it will only dispatch the `onDragStop` event, and not the `onInputUp` event. If set to `false` it will dispatch both events.
186+
*/
187+
this.dragStopBlocksInputUp = false;
188+
184189
/**
185190
* @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.
186191
*/
@@ -1117,7 +1122,11 @@ Phaser.InputHandler.prototype = {
11171122

11181123
if (this.sprite && this.sprite.events)
11191124
{
1120-
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, isOver);
1125+
if (!this.dragStopBlocksInputUp ||
1126+
this.dragStopBlocksInputUp && !(this.draggable && this.isDragged && this._draggedPointerID === pointer.id))
1127+
{
1128+
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, isOver);
1129+
}
11211130

11221131
// The onInputUp event may have changed the sprite so that checkPointerOver is no longer true, so update it.
11231132
if (isOver)

typescript/phaser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,7 @@ declare module "phaser" {
19601960
dragFromCenter: boolean;
19611961
draggable: boolean;
19621962
dragStartPoint: Phaser.Point;
1963+
dragStopBlocksInputUp: boolean;
19631964
dragTimeThreshold: number;
19641965
enabled: boolean;
19651966
game: Phaser.Game;

0 commit comments

Comments
 (0)