mirror of
https://github.com/wassname/phaser.git
synced 2026-09-12 12:40:47 +08:00
Fixed world drag support and other input modifications.
This commit is contained in:
+45
-41
@@ -42,11 +42,15 @@ module Phaser {
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
this.scale = new Vec2(1, 1);
|
||||
this.speed = new Vec2;
|
||||
this.position = new Vec2;
|
||||
this._oldPosition = new Vec2;
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
|
||||
this.camera = this._game.camera;
|
||||
|
||||
this.activePointer = this.mousePointer;
|
||||
this.currentPointers = 0;
|
||||
|
||||
}
|
||||
@@ -63,6 +67,20 @@ module Phaser {
|
||||
**/
|
||||
private _oldPosition: Vec2 = null;
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _x: number = 0;
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _y: number = 0;
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
|
||||
* If you need to disable just one type of input, for example mouse, use Input.mouse.disabled = true instead
|
||||
@@ -93,6 +111,13 @@ module Phaser {
|
||||
*/
|
||||
public static MOUSE_TOUCH_COMBINE: number = 2;
|
||||
|
||||
/**
|
||||
* The camera being used for mouse and touch based pointers to calculate their world coordinates.
|
||||
* @property camera
|
||||
* @type {Camera}
|
||||
**/
|
||||
public camera: Camera;
|
||||
|
||||
/**
|
||||
* Phaser.Mouse handler
|
||||
* @type {Mouse}
|
||||
@@ -147,30 +172,11 @@ module Phaser {
|
||||
public circle: Circle = null;
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _x: number = 0;
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _y: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Number}
|
||||
* The scale by which all input coordinates are multiplied, calculated by the StageScaleMode.
|
||||
* In an un-scaled game the values will be x: 1 and y: 1.
|
||||
* @type {Vec2}
|
||||
*/
|
||||
public scaleX: number = 1;
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
public scaleY: number = 1;
|
||||
public scale: Vec2 = null;
|
||||
|
||||
/**
|
||||
* The maximum number of Pointers allowed to be active at any one time.
|
||||
@@ -347,37 +353,39 @@ module Phaser {
|
||||
public pointer10: Pointer = null;
|
||||
|
||||
/**
|
||||
* The screen X coordinate
|
||||
* The most recently active Pointer object.
|
||||
* When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.
|
||||
* @property activePointer
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public activePointer: Pointer = null;
|
||||
|
||||
/**
|
||||
* The X coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
**/
|
||||
public get x(): number {
|
||||
|
||||
return this._x;
|
||||
|
||||
}
|
||||
|
||||
public set x(value: number) {
|
||||
|
||||
this._x = Math.round(value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The screen Y coordinate
|
||||
* The Y coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
**/
|
||||
public get y(): number {
|
||||
|
||||
return this._y;
|
||||
|
||||
}
|
||||
|
||||
public set y(value: number) {
|
||||
|
||||
this._y = Math.round(value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,7 +477,6 @@ module Phaser {
|
||||
**/
|
||||
public update() {
|
||||
|
||||
// Swap for velocity vector - and add it to Pointer?
|
||||
this.speed.x = this.position.x - this._oldPosition.x;
|
||||
this.speed.y = this.position.y - this._oldPosition.y;
|
||||
|
||||
@@ -488,6 +495,7 @@ module Phaser {
|
||||
if (this.pointer9) { this.pointer9.update(); }
|
||||
if (this.pointer10) { this.pointer10.update(); }
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -883,18 +891,14 @@ module Phaser {
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldX(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.x + this.x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldY(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.y + this.y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -904,12 +908,12 @@ module Phaser {
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.font = '14px Courier';
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Input', x, y);
|
||||
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
|
||||
this._game.stage.context.fillText('X: ' + this.x + ' Y: ' + this.y, x, y + 14);
|
||||
this._game.stage.context.fillText('World X: ' + this.getWorldX() + ' World Y: ' + this.getWorldY(), x, y + 28);
|
||||
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
|
||||
this._game.stage.context.fillText('Scale X: ' + this.scale.x.toFixed(1) + ' Scale Y: ' + this.scale.x.toFixed(1), x, y + 42);
|
||||
this._game.stage.context.fillText('Screen X: ' + this.activePointer.screenX + ' Screen Y: ' + this.activePointer.screenY, x, y + 56);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+18
-34
@@ -170,14 +170,14 @@ module Phaser {
|
||||
public screenY: number = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the game element
|
||||
* The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
*/
|
||||
public x: number = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the game element
|
||||
* The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
*/
|
||||
@@ -263,39 +263,19 @@ module Phaser {
|
||||
public targetObject = null;
|
||||
|
||||
/**
|
||||
* Gets the X value of this Pointer in world coordinate space (is it properly scaled?)
|
||||
* Gets the X value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldX(camera?: Camera = this.game.camera) {
|
||||
|
||||
public worldX(camera?: Camera = this.game.input.camera) {
|
||||
return camera.worldView.x + this.x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Y value of this Pointer in world coordinate space
|
||||
* Gets the Y value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldY(camera?: Camera = this.game.camera) {
|
||||
|
||||
public worldY(camera?: Camera = this.game.input.camera) {
|
||||
return camera.worldView.y + this.y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the X value of this Pointer in world coordinate space
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public get scaledX():number {
|
||||
return Math.floor(this.x * this.game.input.scaleX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Y value of this Pointer in world coordinate space
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public get scaledY():number {
|
||||
return Math.floor(this.y * this.game.input.scaleY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,15 +309,18 @@ module Phaser {
|
||||
this.timeDown = this.game.time.now;
|
||||
this._holdSent = false;
|
||||
|
||||
// This sets the x/y and other local values
|
||||
this.move(event);
|
||||
|
||||
// x and y are the old values here?
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
|
||||
this.move(event);
|
||||
|
||||
if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
|
||||
{
|
||||
this.game.input.x = this.x * this.game.input.scaleX;
|
||||
this.game.input.y = this.y * this.game.input.scaleY;
|
||||
//this.game.input.x = this.x * this.game.input.scale.x;
|
||||
//this.game.input.y = this.y * this.game.input.scale.y;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.onDown.dispatch(this);
|
||||
}
|
||||
|
||||
@@ -407,8 +390,8 @@ module Phaser {
|
||||
this.screenX = event.screenX;
|
||||
this.screenY = event.screenY;
|
||||
|
||||
this.x = this.pageX - this.game.stage.offset.x;
|
||||
this.y = this.pageY - this.game.stage.offset.y;
|
||||
this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
|
||||
this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
|
||||
|
||||
this.position.setTo(this.x, this.y);
|
||||
this.circle.x = this.x;
|
||||
@@ -416,8 +399,9 @@ module Phaser {
|
||||
|
||||
if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
|
||||
{
|
||||
this.game.input.x = this.x * this.game.input.scaleX;
|
||||
this.game.input.y = this.y * this.game.input.scaleY;
|
||||
this.game.input.activePointer = this;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.position.setTo(this.game.input.x, this.game.input.y);
|
||||
this.game.input.circle.x = this.game.input.x;
|
||||
this.game.input.circle.y = this.game.input.y;
|
||||
|
||||
Reference in New Issue
Block a user