mirror of
https://github.com/wassname/phaser.git
synced 2026-07-08 00:10:32 +08:00
Fixed drag sprite + offsets and center locking
This commit is contained in:
@@ -302,10 +302,19 @@ module Phaser.Components {
|
||||
|
||||
public _touchedHandler(pointer: Pointer) {
|
||||
|
||||
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);
|
||||
if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true)
|
||||
{
|
||||
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)
|
||||
{
|
||||
this.startDrag(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -330,15 +339,15 @@ module Phaser.Components {
|
||||
this.stopDrag(pointer);
|
||||
return;
|
||||
}
|
||||
// something wrong here, should use _dragPoint as well I think somehow
|
||||
|
||||
if (this.allowHorizontalDrag)
|
||||
{
|
||||
this._sprite.x = pointer.x - this.dragOffset.x;
|
||||
this._sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
|
||||
}
|
||||
|
||||
if (this.allowVerticalDrag)
|
||||
{
|
||||
this._sprite.y = pointer.y - this.dragOffset.y;
|
||||
this._sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
|
||||
}
|
||||
|
||||
if (this.boundsRect)
|
||||
@@ -481,13 +490,15 @@ module Phaser.Components {
|
||||
{
|
||||
this._pointerData[pointer.id].isDragged = true;
|
||||
|
||||
if (this.dragFromCenter)
|
||||
{
|
||||
// Move the sprite to the middle of the pointer
|
||||
this.dragOffset.setTo(this._sprite.frameBounds.halfWidth, this._sprite.frameBounds.halfHeight);
|
||||
}
|
||||
|
||||
this._dragPoint.setTo(pointer.x - this._sprite.x - this.dragOffset.x, pointer.y - this._sprite.y - this.dragOffset.y);
|
||||
if (this.dragFromCenter)
|
||||
{
|
||||
// Move the sprite to the middle of the pointer
|
||||
this._dragPoint.setTo(-this._sprite.frameBounds.halfWidth, -this._sprite.frameBounds.halfHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ TODO:
|
||||
* Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
||||
* Bug: Sprite x/y gets shifted if dynamic from the original value
|
||||
* Input CSS cursor those little 4-way arrows on drag?
|
||||
* Stage CSS3 transforms!!! Color tints, sepia, greyscale, all of those cool things :)
|
||||
|
||||
|
||||
V1.0.0
|
||||
|
||||
|
||||
@@ -80,6 +80,10 @@
|
||||
<Content Include="groups\swap children.js">
|
||||
<DependentUpon>swap children.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="input\drag sprite 1.ts" />
|
||||
<Content Include="input\drag sprite 1.js">
|
||||
<DependentUpon>drag sprite 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="input\over sprite 1.js">
|
||||
<DependentUpon>over sprite 1.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
@@ -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/atari130xe.png');
|
||||
game.loader.load();
|
||||
}
|
||||
var sprite;
|
||||
function create() {
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
// Enable Input detection
|
||||
sprite.input.start(0, false, true);
|
||||
sprite.input.enableDrag(true);
|
||||
sprite.input.allowVerticalDrag = false;
|
||||
//sprite.input.dragOffset.setTo(0, 50);
|
||||
}
|
||||
function render() {
|
||||
game.input.renderDebugInfo(32, 32);
|
||||
sprite.input.renderDebugInfo(300, 32);
|
||||
}
|
||||
})();
|
||||
@@ -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/atari130xe.png');
|
||||
game.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var sprite: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(200, 200, 'sprite');
|
||||
|
||||
// Enable Input detection
|
||||
sprite.input.start(0, false, true);
|
||||
|
||||
sprite.input.enableDrag(true);
|
||||
|
||||
//sprite.input.allowVerticalDrag = false;
|
||||
//sprite.input.dragOffset.setTo(0, 50);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.input.renderDebugInfo(32, 32);
|
||||
sprite.input.renderDebugInfo(300, 32);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
+15
-9
@@ -5792,10 +5792,16 @@ var Phaser;
|
||||
}
|
||||
};
|
||||
Input.prototype._touchedHandler = function (pointer) {
|
||||
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);
|
||||
if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
|
||||
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) {
|
||||
this.startDrag(pointer);
|
||||
}
|
||||
}
|
||||
};
|
||||
Input.prototype._releasedHandler = function (pointer) {
|
||||
this._pointerData[pointer.id].isDown = false;
|
||||
@@ -5812,12 +5818,11 @@ var Phaser;
|
||||
this.stopDrag(pointer);
|
||||
return;
|
||||
}
|
||||
// something wrong here, should use _dragPoint as well I think somehow
|
||||
if(this.allowHorizontalDrag) {
|
||||
this._sprite.x = pointer.x - this.dragOffset.x;
|
||||
this._sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
|
||||
}
|
||||
if(this.allowVerticalDrag) {
|
||||
this._sprite.y = pointer.y - this.dragOffset.y;
|
||||
this._sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
|
||||
}
|
||||
if(this.boundsRect) {
|
||||
this.checkBoundsRect();
|
||||
@@ -5940,9 +5945,10 @@ var Phaser;
|
||||
this._pointerData[pointer.id].isDragged = true;
|
||||
if(this.dragFromCenter) {
|
||||
// Move the sprite to the middle of the pointer
|
||||
this.dragOffset.setTo(this._sprite.frameBounds.halfWidth, this._sprite.frameBounds.halfHeight);
|
||||
this._dragPoint.setTo(-this._sprite.frameBounds.halfWidth, -this._sprite.frameBounds.halfHeight);
|
||||
} else {
|
||||
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
|
||||
}
|
||||
this._dragPoint.setTo(pointer.x - this._sprite.x - this.dragOffset.x, pointer.y - this._sprite.y - this.dragOffset.y);
|
||||
};
|
||||
Input.prototype.stopDrag = /**
|
||||
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
|
||||
|
||||
+15
-9
@@ -5792,10 +5792,16 @@ var Phaser;
|
||||
}
|
||||
};
|
||||
Input.prototype._touchedHandler = function (pointer) {
|
||||
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);
|
||||
if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
|
||||
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) {
|
||||
this.startDrag(pointer);
|
||||
}
|
||||
}
|
||||
};
|
||||
Input.prototype._releasedHandler = function (pointer) {
|
||||
this._pointerData[pointer.id].isDown = false;
|
||||
@@ -5812,12 +5818,11 @@ var Phaser;
|
||||
this.stopDrag(pointer);
|
||||
return;
|
||||
}
|
||||
// something wrong here, should use _dragPoint as well I think somehow
|
||||
if(this.allowHorizontalDrag) {
|
||||
this._sprite.x = pointer.x - this.dragOffset.x;
|
||||
this._sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
|
||||
}
|
||||
if(this.allowVerticalDrag) {
|
||||
this._sprite.y = pointer.y - this.dragOffset.y;
|
||||
this._sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
|
||||
}
|
||||
if(this.boundsRect) {
|
||||
this.checkBoundsRect();
|
||||
@@ -5940,9 +5945,10 @@ var Phaser;
|
||||
this._pointerData[pointer.id].isDragged = true;
|
||||
if(this.dragFromCenter) {
|
||||
// Move the sprite to the middle of the pointer
|
||||
this.dragOffset.setTo(this._sprite.frameBounds.halfWidth, this._sprite.frameBounds.halfHeight);
|
||||
this._dragPoint.setTo(-this._sprite.frameBounds.halfWidth, -this._sprite.frameBounds.halfHeight);
|
||||
} else {
|
||||
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
|
||||
}
|
||||
this._dragPoint.setTo(pointer.x - this._sprite.x - this.dragOffset.x, pointer.y - this._sprite.y - this.dragOffset.y);
|
||||
};
|
||||
Input.prototype.stopDrag = /**
|
||||
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
|
||||
|
||||
Reference in New Issue
Block a user