diff --git a/examples/drag.php b/examples/drag.php
new file mode 100644
index 00000000..8ee651eb
--- /dev/null
+++ b/examples/drag.php
@@ -0,0 +1,43 @@
+
+
+
+ phaser.js - a new beginning
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/snap.php b/examples/snap.php
new file mode 100644
index 00000000..bbc78ef4
--- /dev/null
+++ b/examples/snap.php
@@ -0,0 +1,54 @@
+
+
+
+ phaser.js - a new beginning
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js
index 1497024f..a9fe40ae 100644
--- a/src/gameobjects/Sprite.js
+++ b/src/gameobjects/Sprite.js
@@ -313,6 +313,17 @@ Phaser.Sprite.prototype.preUpdate = function() {
}
+/**
+ * Moves the sprite so its center is located on the given x and y coordinates.
+ * Doesn't change the origin of the sprite.
+ */
+Phaser.Sprite.prototype.centerOn = function(x, y) {
+
+ this.x = x + (this.x - this.center.x);
+ this.y = y + (this.y - this.center.y);
+
+}
+
Phaser.Sprite.prototype.revive = function() {
this.alive = true;
diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js
index 35173284..41be1595 100644
--- a/src/input/InputHandler.js
+++ b/src/input/InputHandler.js
@@ -649,9 +649,10 @@ Phaser.InputHandler.prototype = {
*/
enableDrag: function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
- lockCenter = lockCenter || false;
- bringToTop = bringToTop || false;
- pixelPerfect = pixelPerfect || false;
+ if (typeof lockCenter == 'undefined') { lockCenter = false; }
+ if (typeof bringToTop == 'undefined') { bringToTop = false; }
+ if (typeof pixelPerfect == 'undefined') { pixelPerfect = false; }
+
alphaThreshold = alphaThreshold || 255;
boundsRect = boundsRect || null;
boundsSprite = boundsSprite || null;
@@ -707,7 +708,7 @@ Phaser.InputHandler.prototype = {
if (this.dragFromCenter)
{
- // this.sprite.transform.centerOn(pointer.worldX, pointer.worldY);
+ this.sprite.centerOn(pointer.x, pointer.y);
this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y);
}
else
@@ -773,13 +774,13 @@ Phaser.InputHandler.prototype = {
*/
enableSnap: function (snapX, snapY, onDrag, onRelease) {
- onDrag = onDrag || true;
- onRelease = onRelease || false;
+ if (typeof onDrag == 'undefined') { onDrag = true; }
+ if (typeof onRelease == 'undefined') { onRelease = false; }
- this.snapOnDrag = onDrag;
- this.snapOnRelease = onRelease;
this.snapX = snapX;
this.snapY = snapY;
+ this.snapOnDrag = onDrag;
+ this.snapOnRelease = onRelease;
},