Input priority IDs working properly for drag events.

This commit is contained in:
Richard Davey 2013-06-03 01:22:14 +01:00
parent 2270da2479
commit b951b02de8
22 changed files with 418 additions and 208 deletions

View file

@ -48,52 +48,10 @@ module Phaser.Components {
*/
public priorityID:number = 0;
public start(priority:number = 0, checkBody?:bool = false, useHandCursor?:bool = false) {
// Turning on
if (this.enabled)
{
return;
}
else
{
// Register, etc
this.checkBody = checkBody;
this.useHandCursor = useHandCursor;
this._pointerData = [];
for (var i = 0; i < 10; i++)
{
this._pointerData.push({ id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, timeDown: 0, timeUp: 0, downDuration: 0, isDragged: false });
}
this.snapOffset = new Point;
this.enabled = true;
this.game.input.addGameObject(this._sprite);
}
}
public stop() {
// Turning off
if (this.enabled == false)
{
return;
}
else
{
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
}
}
private _dragPoint: Point;
private _draggedPointerID: number;
public dragOffset: Point;
public isDragged: bool = false;
public dragFromCenter: bool;
public dragPixelPerfect:bool = false;
public dragPixelPerfectAlpha:number;
@ -238,26 +196,62 @@ module Phaser.Components {
return this._pointerData[pointer].isDragged;
}
/**
* Update
*/
public update(pointer: Phaser.Pointer) {
public start(priority:number = 0, checkBody?:bool = false, useHandCursor?:bool = false): Sprite {
// Turning on
if (this.enabled == false)
{
// Register, etc
this.checkBody = checkBody;
this.useHandCursor = useHandCursor;
this.priorityID = priority;
this._pointerData = [];
for (var i = 0; i < 10; i++)
{
this._pointerData.push({ id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, timeDown: 0, timeUp: 0, downDuration: 0, isDragged: false });
}
this.snapOffset = new Point;
this.enabled = true;
this.game.input.addGameObject(this._sprite);
}
return this._sprite;
}
public stop() {
// Turning off
if (this.enabled == false)
{
return;
}
// If was previously touched by this Pointer, check if still is
if (this._pointerData[pointer.id].isDown && pointer.isUp)
else
{
this._releasedHandler(pointer);
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
}
if (this.draggable && this._pointerData[pointer.id].isDragged)
}
/**
* Update
*/
public update(pointer: Phaser.Pointer): bool {
if (this.enabled == false)
{
return false;
}
if (this.draggable && this._draggedPointerID == pointer.id)
{
this.updateDrag(pointer);
//return;
}
if (RectangleUtils.contains(this._sprite.frameBounds, pointer.x, pointer.y))
@ -280,6 +274,8 @@ module Phaser.Components {
this._sprite.events.onInputOver.dispatch(this._sprite, pointer);
}
return true;
}
else
{
@ -296,6 +292,8 @@ module Phaser.Components {
this._sprite.events.onInputOut.dispatch(this._sprite, pointer);
}
return false;
}
}
@ -307,25 +305,42 @@ module Phaser.Components {
this._pointerData[pointer.id].isDown = true;
this._pointerData[pointer.id].isUp = false;
this._pointerData[pointer.id].timeDown = this.game.time.now;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
// Star drag
if (this.draggable)
// Start drag
if (this.draggable && this.isDragged == false && pointer.draggedObject == null)
{
this.startDrag(pointer);
}
}
}
public _releasedHandler(pointer: Pointer) {
// If was previously touched by this Pointer, check if still is
if (this._pointerData[pointer.id].isDown && pointer.isUp)
{
this._pointerData[pointer.id].isDown = false;
this._pointerData[pointer.id].isUp = true;
this._pointerData[pointer.id].timeUp = this.game.time.now;
//this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
this._sprite.events.onInputUp.dispatch(this._sprite, pointer);
// Stop drag
if (this.draggable && this.isDragged && this._draggedPointerID == pointer.id)
{
this.stopDrag(pointer);
}
if (this.useHandCursor)
{
this.game.stage.canvas.style.cursor = "default";
}
}
}
@ -478,9 +493,8 @@ module Phaser.Components {
}
this.draggable = false;
//mouseStartDragCallback = null;
//mouseStopDragCallback = null;
this.isDragged = false;
this._draggedPointerID = -1;
}
/**
@ -488,6 +502,8 @@ module Phaser.Components {
*/
public startDrag(pointer: Pointer):void
{
this.isDragged = true;
this._draggedPointerID = pointer.id;
this._pointerData[pointer.id].isDragged = true;
if (this.dragFromCenter)
@ -500,6 +516,8 @@ module Phaser.Components {
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
}
pointer.draggedObject = this._sprite;
}
/**
@ -507,6 +525,8 @@ module Phaser.Components {
*/
public stopDrag(pointer: Pointer):void
{
this.isDragged = false;
this._draggedPointerID = -1;
this._pointerData[pointer.id].isDragged = false;
if (this.snapOnRelease)
@ -514,6 +534,8 @@ module Phaser.Components {
this._sprite.x = Math.floor(this._sprite.x / this.snapX) * this.snapX;
this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY;
}
pointer.draggedObject = null;
}
/**

View file

@ -252,8 +252,6 @@ module Phaser {
}
// Sprite Drag Related
/**
* The Game Object this Pointer is currently dragging.
* @property draggedObject
@ -369,15 +367,15 @@ module Phaser {
{
if (this.game.input.inputObjects[i].input.enabled)
{
this.game.input.inputObjects[i].input.update(this);
if (this.game.input.inputObjects[i].input.priorityID > _highestPriority)
if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority)
{
_highestPriority = this.game.input.inputObjects[i].input.priorityID;
}
}
}
//console.log('highest priority was', _highestPriority);
if (this.isDown)
{
// Now update all objects with the highest priority ID (can be more than 1)
@ -493,6 +491,16 @@ module Phaser {
this.game.input.currentPointers--;
}
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
{
if (this.game.input.inputObjects[i].input.enabled)
{
this.game.input.inputObjects[i].input._releasedHandler(this);
}
}
this.draggedObject = null;
return this;
}

View file

@ -84,6 +84,10 @@
<Content Include="input\drag sprite 1.js">
<DependentUpon>drag sprite 1.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="input\drag sprite 2.ts" />
<Content Include="input\drag sprite 2.js">
<DependentUpon>drag sprite 2.ts</DependentUpon>
</Content>
<Content Include="input\over sprite 1.js">
<DependentUpon>over sprite 1.ts</DependentUpon>
</Content>
@ -91,6 +95,10 @@
<Content Include="input\over sprite 2.js">
<DependentUpon>over sprite 2.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="input\touch priority.ts" />
<Content Include="input\touch priority.js">
<DependentUpon>touch priority.ts</DependentUpon>
</Content>
<Content Include="particles\graphic emitter.js">
<DependentUpon>graphic emitter.ts</DependentUpon>
</Content>

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -9,11 +9,12 @@
var sprite;
function create() {
sprite = game.add.sprite(200, 200, 'sprite');
// Enable Input detection
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.input.start(0, false, true);
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag(true);
sprite.input.allowVerticalDrag = false;
//sprite.input.dragOffset.setTo(0, 50);
}
function render() {
game.input.renderDebugInfo(32, 32);

View file

@ -18,14 +18,14 @@
sprite = game.add.sprite(200, 200, 'sprite');
// Enable Input detection
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.input.start(0, false, true);
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag(true);
//sprite.input.allowVerticalDrag = false;
//sprite.input.dragOffset.setTo(0, 50);
}
function render() {

View file

@ -0,0 +1,22 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('sprite', 'assets/sprites/atari800.png');
game.loader.load();
}
var sprite;
function create() {
sprite = game.add.sprite(200, 200, 'sprite');
sprite.input.start(0, false, true);
sprite.input.enableDrag(true);
// The drag offset allows us to position the sprite relative to the pointer (+ lock) position
// In this case it will be positioned -100px above the pointer
sprite.input.dragOffset.y = -100;
}
function render() {
game.input.renderDebugInfo(32, 32);
sprite.input.renderDebugInfo(300, 32);
}
})();

View file

@ -0,0 +1,38 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('sprite', 'assets/sprites/atari800.png');
game.loader.load();
}
var sprite: Phaser.Sprite;
function create() {
sprite = game.add.sprite(200, 200, 'sprite');
sprite.input.start(0, false, true);
sprite.input.enableDrag(true);
// The drag offset allows us to position the sprite relative to the pointer (+ lock) position
// In this case it will be positioned -100px above the pointer
sprite.input.dragOffset.y = -100;
}
function render() {
game.input.renderDebugInfo(32, 32);
sprite.input.renderDebugInfo(300, 32);
}
})();

View file

@ -0,0 +1,28 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari1', 'assets/sprites/atari130xe.png');
game.loader.addImageFile('atari2', 'assets/sprites/atari800xl.png');
game.loader.addImageFile('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.loader.load();
}
var atari1;
var atari2;
var sonic;
function create() {
atari1 = game.add.sprite(100, 100, 'atari1');
atari2 = game.add.sprite(300, 200, 'atari2');
sonic = game.add.sprite(400, 300, 'sonic');
atari1.input.start(0, false, true);
atari2.input.start(1, false, true);
sonic.input.start(2, false, true);
atari1.input.enableDrag();
atari2.input.enableDrag();
sonic.input.enableDrag();
}
function render() {
game.input.renderDebugInfo(32, 32);
}
})();

View file

@ -0,0 +1,41 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari1', 'assets/sprites/atari130xe.png');
game.loader.addImageFile('atari2', 'assets/sprites/atari800xl.png');
game.loader.addImageFile('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.loader.load();
}
var atari1: Phaser.Sprite;
var atari2: Phaser.Sprite;
var sonic: Phaser.Sprite;
function create() {
atari1 = game.add.sprite(100, 100, 'atari1');
atari2 = game.add.sprite(300, 200, 'atari2');
sonic = game.add.sprite(400, 300, 'sonic');
atari1.input.start(0, false, true);
atari2.input.start(1, false, true);
sonic.input.start(2, false, true);
atari1.input.enableDrag();
atari2.input.enableDrag();
sonic.input.enableDrag();
}
function render() {
game.input.renderDebugInfo(32, 32);
}
})();

View file

@ -5583,6 +5583,7 @@ var Phaser;
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
*/
this.priorityID = 0;
this.isDragged = false;
this.dragPixelPerfect = false;
this.allowHorizontalDrag = true;
this.allowVerticalDrag = true;
@ -5609,50 +5610,6 @@ var Phaser;
this._sprite = parent;
this.enabled = false;
}
Input.prototype.start = function (priority, checkBody, useHandCursor) {
if (typeof priority === "undefined") { priority = 0; }
if (typeof checkBody === "undefined") { checkBody = false; }
if (typeof useHandCursor === "undefined") { useHandCursor = false; }
// Turning on
if(this.enabled) {
return;
} else {
// Register, etc
this.checkBody = checkBody;
this.useHandCursor = useHandCursor;
this._pointerData = [];
for(var i = 0; i < 10; i++) {
this._pointerData.push({
id: i,
x: 0,
y: 0,
isDown: false,
isUp: false,
isOver: false,
isOut: false,
timeOver: 0,
timeOut: 0,
timeDown: 0,
timeUp: 0,
downDuration: 0,
isDragged: false
});
}
this.snapOffset = new Phaser.Point();
this.enabled = true;
this.game.input.addGameObject(this._sprite);
}
};
Input.prototype.stop = function () {
// Turning off
if(this.enabled == false) {
return;
} else {
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
}
};
Input.prototype.pointerX = /**
* The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
* This value is only set when the pointer is over this Sprite.
@ -5751,20 +5708,59 @@ var Phaser;
if (typeof pointer === "undefined") { pointer = 0; }
return this._pointerData[pointer].isDragged;
};
Input.prototype.start = function (priority, checkBody, useHandCursor) {
if (typeof priority === "undefined") { priority = 0; }
if (typeof checkBody === "undefined") { checkBody = false; }
if (typeof useHandCursor === "undefined") { useHandCursor = false; }
// Turning on
if(this.enabled == false) {
// Register, etc
this.checkBody = checkBody;
this.useHandCursor = useHandCursor;
this.priorityID = priority;
this._pointerData = [];
for(var i = 0; i < 10; i++) {
this._pointerData.push({
id: i,
x: 0,
y: 0,
isDown: false,
isUp: false,
isOver: false,
isOut: false,
timeOver: 0,
timeOut: 0,
timeDown: 0,
timeUp: 0,
downDuration: 0,
isDragged: false
});
}
this.snapOffset = new Phaser.Point();
this.enabled = true;
this.game.input.addGameObject(this._sprite);
}
return this._sprite;
};
Input.prototype.stop = function () {
// Turning off
if(this.enabled == false) {
return;
} else {
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
}
};
Input.prototype.update = /**
* Update
*/
function (pointer) {
if(this.enabled == false) {
return;
return false;
}
// If was previously touched by this Pointer, check if still is
if(this._pointerData[pointer.id].isDown && pointer.isUp) {
this._releasedHandler(pointer);
}
if(this.draggable && this._pointerData[pointer.id].isDragged) {
if(this.draggable && this._draggedPointerID == pointer.id) {
this.updateDrag(pointer);
//return;
}
if(Phaser.RectangleUtils.contains(this._sprite.frameBounds, pointer.x, pointer.y)) {
// { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false }
@ -5779,6 +5775,7 @@ var Phaser;
}
this._sprite.events.onInputOver.dispatch(this._sprite, pointer);
}
return true;
} else {
if(this._pointerData[pointer.id].isOver) {
this._pointerData[pointer.id].isOver = false;
@ -5789,6 +5786,7 @@ var Phaser;
}
this._sprite.events.onInputOut.dispatch(this._sprite, pointer);
}
return false;
}
};
Input.prototype._touchedHandler = function (pointer) {
@ -5797,18 +5795,28 @@ var Phaser;
this._pointerData[pointer.id].isUp = false;
this._pointerData[pointer.id].timeDown = this.game.time.now;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
// Star drag
if(this.draggable) {
// Start drag
if(this.draggable && this.isDragged == false && pointer.draggedObject == null) {
this.startDrag(pointer);
}
}
};
Input.prototype._releasedHandler = function (pointer) {
// If was previously touched by this Pointer, check if still is
if(this._pointerData[pointer.id].isDown && pointer.isUp) {
this._pointerData[pointer.id].isDown = false;
this._pointerData[pointer.id].isUp = true;
this._pointerData[pointer.id].timeUp = this.game.time.now;
//this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._sprite.events.onInputUp.dispatch(this._sprite, pointer);
// Stop drag
if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
this.stopDrag(pointer);
}
if(this.useHandCursor) {
this.game.stage.canvas.style.cursor = "default";
}
}
};
Input.prototype.updateDrag = /**
* Updates the Pointer drag on this Sprite.
@ -5935,13 +5943,15 @@ var Phaser;
}
}
this.draggable = false;
//mouseStartDragCallback = null;
//mouseStopDragCallback = null;
this.isDragged = false;
this._draggedPointerID = -1;
};
Input.prototype.startDrag = /**
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
*/
function (pointer) {
this.isDragged = true;
this._draggedPointerID = pointer.id;
this._pointerData[pointer.id].isDragged = true;
if(this.dragFromCenter) {
// Move the sprite to the middle of the pointer
@ -5949,16 +5959,20 @@ var Phaser;
} else {
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
}
pointer.draggedObject = this._sprite;
};
Input.prototype.stopDrag = /**
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
*/
function (pointer) {
this.isDragged = false;
this._draggedPointerID = -1;
this._pointerData[pointer.id].isDragged = false;
if(this.snapOnRelease) {
this._sprite.x = Math.floor(this._sprite.x / this.snapX) * this.snapX;
this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY;
}
pointer.draggedObject = null;
};
Input.prototype.setDragLock = /**
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
@ -13525,12 +13539,12 @@ var Phaser;
var _highestPriority = 0;
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
if(this.game.input.inputObjects[i].input.enabled) {
this.game.input.inputObjects[i].input.update(this);
if(this.game.input.inputObjects[i].input.priorityID > _highestPriority) {
if(this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority) {
_highestPriority = this.game.input.inputObjects[i].input.priorityID;
}
}
}
//console.log('highest priority was', _highestPriority);
if(this.isDown) {
// Now update all objects with the highest priority ID (can be more than 1)
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
@ -13611,6 +13625,12 @@ var Phaser;
if(this.isMouse == false) {
this.game.input.currentPointers--;
}
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
if(this.game.input.inputObjects[i].input.enabled) {
this.game.input.inputObjects[i].input._releasedHandler(this);
}
}
this.draggedObject = null;
return this;
};
Pointer.prototype.justPressed = /**

8
build/phaser.d.ts vendored
View file

@ -3271,10 +3271,10 @@ module Phaser.Components {
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
*/
public priorityID: number;
public start(priority?: number, checkBody?: bool, useHandCursor?: bool): void;
public stop(): void;
private _dragPoint;
private _draggedPointerID;
public dragOffset: Point;
public isDragged: bool;
public dragFromCenter: bool;
public dragPixelPerfect: bool;
public dragPixelPerfectAlpha: number;
@ -3377,10 +3377,12 @@ module Phaser.Components {
* @default false
*/
public pointerDragged(pointer?: number): bool;
public start(priority?: number, checkBody?: bool, useHandCursor?: bool): Sprite;
public stop(): void;
/**
* Update
*/
public update(pointer: Pointer): void;
public update(pointer: Pointer): bool;
public _touchedHandler(pointer: Pointer): void;
public _releasedHandler(pointer: Pointer): void;
/**

View file

@ -5583,6 +5583,7 @@ var Phaser;
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
*/
this.priorityID = 0;
this.isDragged = false;
this.dragPixelPerfect = false;
this.allowHorizontalDrag = true;
this.allowVerticalDrag = true;
@ -5609,50 +5610,6 @@ var Phaser;
this._sprite = parent;
this.enabled = false;
}
Input.prototype.start = function (priority, checkBody, useHandCursor) {
if (typeof priority === "undefined") { priority = 0; }
if (typeof checkBody === "undefined") { checkBody = false; }
if (typeof useHandCursor === "undefined") { useHandCursor = false; }
// Turning on
if(this.enabled) {
return;
} else {
// Register, etc
this.checkBody = checkBody;
this.useHandCursor = useHandCursor;
this._pointerData = [];
for(var i = 0; i < 10; i++) {
this._pointerData.push({
id: i,
x: 0,
y: 0,
isDown: false,
isUp: false,
isOver: false,
isOut: false,
timeOver: 0,
timeOut: 0,
timeDown: 0,
timeUp: 0,
downDuration: 0,
isDragged: false
});
}
this.snapOffset = new Phaser.Point();
this.enabled = true;
this.game.input.addGameObject(this._sprite);
}
};
Input.prototype.stop = function () {
// Turning off
if(this.enabled == false) {
return;
} else {
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
}
};
Input.prototype.pointerX = /**
* The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
* This value is only set when the pointer is over this Sprite.
@ -5751,20 +5708,59 @@ var Phaser;
if (typeof pointer === "undefined") { pointer = 0; }
return this._pointerData[pointer].isDragged;
};
Input.prototype.start = function (priority, checkBody, useHandCursor) {
if (typeof priority === "undefined") { priority = 0; }
if (typeof checkBody === "undefined") { checkBody = false; }
if (typeof useHandCursor === "undefined") { useHandCursor = false; }
// Turning on
if(this.enabled == false) {
// Register, etc
this.checkBody = checkBody;
this.useHandCursor = useHandCursor;
this.priorityID = priority;
this._pointerData = [];
for(var i = 0; i < 10; i++) {
this._pointerData.push({
id: i,
x: 0,
y: 0,
isDown: false,
isUp: false,
isOver: false,
isOut: false,
timeOver: 0,
timeOut: 0,
timeDown: 0,
timeUp: 0,
downDuration: 0,
isDragged: false
});
}
this.snapOffset = new Phaser.Point();
this.enabled = true;
this.game.input.addGameObject(this._sprite);
}
return this._sprite;
};
Input.prototype.stop = function () {
// Turning off
if(this.enabled == false) {
return;
} else {
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
}
};
Input.prototype.update = /**
* Update
*/
function (pointer) {
if(this.enabled == false) {
return;
return false;
}
// If was previously touched by this Pointer, check if still is
if(this._pointerData[pointer.id].isDown && pointer.isUp) {
this._releasedHandler(pointer);
}
if(this.draggable && this._pointerData[pointer.id].isDragged) {
if(this.draggable && this._draggedPointerID == pointer.id) {
this.updateDrag(pointer);
//return;
}
if(Phaser.RectangleUtils.contains(this._sprite.frameBounds, pointer.x, pointer.y)) {
// { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false }
@ -5779,6 +5775,7 @@ var Phaser;
}
this._sprite.events.onInputOver.dispatch(this._sprite, pointer);
}
return true;
} else {
if(this._pointerData[pointer.id].isOver) {
this._pointerData[pointer.id].isOver = false;
@ -5789,6 +5786,7 @@ var Phaser;
}
this._sprite.events.onInputOut.dispatch(this._sprite, pointer);
}
return false;
}
};
Input.prototype._touchedHandler = function (pointer) {
@ -5797,18 +5795,28 @@ var Phaser;
this._pointerData[pointer.id].isUp = false;
this._pointerData[pointer.id].timeDown = this.game.time.now;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
// Star drag
if(this.draggable) {
// Start drag
if(this.draggable && this.isDragged == false && pointer.draggedObject == null) {
this.startDrag(pointer);
}
}
};
Input.prototype._releasedHandler = function (pointer) {
// If was previously touched by this Pointer, check if still is
if(this._pointerData[pointer.id].isDown && pointer.isUp) {
this._pointerData[pointer.id].isDown = false;
this._pointerData[pointer.id].isUp = true;
this._pointerData[pointer.id].timeUp = this.game.time.now;
//this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._sprite.events.onInputUp.dispatch(this._sprite, pointer);
// Stop drag
if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
this.stopDrag(pointer);
}
if(this.useHandCursor) {
this.game.stage.canvas.style.cursor = "default";
}
}
};
Input.prototype.updateDrag = /**
* Updates the Pointer drag on this Sprite.
@ -5935,13 +5943,15 @@ var Phaser;
}
}
this.draggable = false;
//mouseStartDragCallback = null;
//mouseStopDragCallback = null;
this.isDragged = false;
this._draggedPointerID = -1;
};
Input.prototype.startDrag = /**
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
*/
function (pointer) {
this.isDragged = true;
this._draggedPointerID = pointer.id;
this._pointerData[pointer.id].isDragged = true;
if(this.dragFromCenter) {
// Move the sprite to the middle of the pointer
@ -5949,16 +5959,20 @@ var Phaser;
} else {
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
}
pointer.draggedObject = this._sprite;
};
Input.prototype.stopDrag = /**
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
*/
function (pointer) {
this.isDragged = false;
this._draggedPointerID = -1;
this._pointerData[pointer.id].isDragged = false;
if(this.snapOnRelease) {
this._sprite.x = Math.floor(this._sprite.x / this.snapX) * this.snapX;
this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY;
}
pointer.draggedObject = null;
};
Input.prototype.setDragLock = /**
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
@ -13525,12 +13539,12 @@ var Phaser;
var _highestPriority = 0;
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
if(this.game.input.inputObjects[i].input.enabled) {
this.game.input.inputObjects[i].input.update(this);
if(this.game.input.inputObjects[i].input.priorityID > _highestPriority) {
if(this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority) {
_highestPriority = this.game.input.inputObjects[i].input.priorityID;
}
}
}
//console.log('highest priority was', _highestPriority);
if(this.isDown) {
// Now update all objects with the highest priority ID (can be more than 1)
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
@ -13611,6 +13625,12 @@ var Phaser;
if(this.isMouse == false) {
this.game.input.currentPointers--;
}
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
if(this.game.input.inputObjects[i].input.enabled) {
this.game.input.inputObjects[i].input._releasedHandler(this);
}
}
this.draggedObject = null;
return this;
};
Pointer.prototype.justPressed = /**