Skip to content

Commit 7d9c817

Browse files
committed
Dragging a Sprite while the camera was moving would slowly cause the Sprite position to become out of sync the further the camera moved. A Sprite being dragged now tracks the camera position during the drag update and adjusts accordingly (thanks @jeroenverfallie phaserjs#1044)
1 parent 628dd1c commit 7d9c817

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
405405
* P2.World.updateBoundsCollisionGroup didn't set the `_boundsOwnGroup` private var, meaning the `World.setBounds` method wasn't able to restore previously set collision masks automatically (thanks @jmp909 #2183)
406406
* P2.World.setBounds has been re-written completely. If the World is resized it no longer removes the P2 body instances and re-creates them. Instead it checks to see which walls are required and then just moves the position of the shapes instead, or updates them, or creates or destroys them as required. This is far more efficient, especially in a game which sees a lot of world bounds changes (i.e. resizes responsively in browser)
407407
* BitmapText would throw an error if you passed in a number as the text property to the constructor. It worked if you used the text accessor directly because it cast the value to a string, but the constructor missed out this step (thanks @lewispollard #2429)
408+
* Dragging a Sprite while the camera was moving would slowly cause the Sprite position to become out of sync the further the camera moved. A Sprite being dragged now tracks the camera position during the drag update and adjusts accordingly (thanks @jeroenverfallie #1044)
408409

409410
### Pixi Updates
410411

src/input/InputHandler.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ Phaser.InputHandler = function (sprite) {
225225
id: 0,
226226
x: 0,
227227
y: 0,
228+
camX: 0,
229+
camY: 0,
228230
isDown: false,
229231
isUp: false,
230232
isOver: false,
@@ -1093,14 +1095,17 @@ Phaser.InputHandler.prototype = {
10931095
}
10941096
else
10951097
{
1098+
var cx = this.game.camera.x - this._pointerData[pointer.id].camX;
1099+
var cy = this.game.camera.y - this._pointerData[pointer.id].camY;
1100+
10961101
if (this.allowHorizontalDrag)
10971102
{
1098-
this.sprite.x = px;
1103+
this.sprite.x = px + cx;
10991104
}
11001105

11011106
if (this.allowVerticalDrag)
11021107
{
1103-
this.sprite.y = py;
1108+
this.sprite.y = py + cy;
11041109
}
11051110

11061111
if (this.boundsRect)
@@ -1318,6 +1323,10 @@ Phaser.InputHandler.prototype = {
13181323

13191324
this.isDragged = true;
13201325
this._draggedPointerID = pointer.id;
1326+
1327+
this._pointerData[pointer.id].camX = this.game.camera.x;
1328+
this._pointerData[pointer.id].camY = this.game.camera.y;
1329+
13211330
this._pointerData[pointer.id].isDragged = true;
13221331

13231332
if (this.sprite.fixedToCamera)

0 commit comments

Comments
 (0)