Skip to content

Commit

Permalink
If an object was drag enabled with bringToTop, the onDragStop event w…
Browse files Browse the repository at this point in the history
…ouldn't fire until the mouse was next moved (thanks @AlperA, fix phaserjs#813)
  • Loading branch information
photonstorm committed May 14, 2014
1 parent bdcc9fc commit b90bcc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Version 2.0.5 - "Tanchico" - in development
* Stage.backgroundColor now properly accepts hex #RRGGBB and color values 0xRRGGBB again (fix #785)
* Color.getRGB would return incorrect color components if a color value without alpha was given, now works with both 0xRRGGBB and 0xAARRGGBB.
* Color.getWebRGB now works regardless if you give an 0xRRGGBB or 0xAARRGGBB color value.
* If an object was drag enabled with bringToTop, the onDragStop event wouldn't fire until the mouse was next moved (thanks @alpera, fix #813)


### To Do
Expand Down
20 changes: 19 additions & 1 deletion src/input/InputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ Phaser.InputHandler = function (sprite) {
*/
this.consumePointerEvent = false;

/**
* @property {boolean} _dragPhase - Internal cache var.
* @private
*/
this._dragPhase = false;

/**
* @property {boolean} _wasEnabled - Internal cache var.
* @private
Expand Down Expand Up @@ -273,6 +279,11 @@ Phaser.InputHandler.prototype = {
*/
addedToGroup: function () {

if (this._dragPhase)
{
return;
}

if (this._wasEnabled && !this.enabled)
{
this.start();
Expand All @@ -288,6 +299,11 @@ Phaser.InputHandler.prototype = {
*/
removedFromGroup: function () {

if (this._dragPhase)
{
return;
}

if (this.enabled)
{
this._wasEnabled = true;
Expand Down Expand Up @@ -907,7 +923,7 @@ Phaser.InputHandler.prototype = {
}

// Stop drag
if (this.draggable && this.isDragged && this._draggedPointerID == pointer.id)
if (this.draggable && this.isDragged && this._draggedPointerID === pointer.id)
{
this.stopDrag(pointer);
}
Expand Down Expand Up @@ -1194,6 +1210,7 @@ Phaser.InputHandler.prototype = {

if (this.bringToTop)
{
this._dragPhase = true;
this.sprite.bringToTop();
}

Expand All @@ -1211,6 +1228,7 @@ Phaser.InputHandler.prototype = {
this.isDragged = false;
this._draggedPointerID = -1;
this._pointerData[pointer.id].isDragged = false;
this._dragPhase = false;

if (this.snapOnRelease)
{
Expand Down
2 changes: 1 addition & 1 deletion src/input/Pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ Phaser.Pointer.prototype = {

this.timeUp = this.game.time.now;

if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
if (this.game.input.multiInputOverride === Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride === Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride === Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
{
this.game.input.onUp.dispatch(this, event);

Expand Down

0 comments on commit b90bcc4

Please sign in to comment.