Skip to content

Commit 5dd75b6

Browse files
committed
Pointer.updateWorldPoint is a new method that takes a Camera and then updates the Pointers worldX and worldY values based on the cameras transform
1 parent 692e0b1 commit 5dd75b6

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
* `Triangle.type` is a new property containing the shapes geometry type, which can be used for quick type comparisons.
8888
* `InputPlugin.enableDebug` is a new method that will create a debug shape for the given Game Objects hit area. This allows you to quickly check the size and placement of an input hit area. You can customzie the shape outline color. The debug shape will automatically track the Game Object to which it is bound.
8989
* `InputPlugion.removeDebug` will remove a Debug Input Shape from the given Game Object and destroy it.
90+
* `Pointer.updateWorldPoint` is a new method that takes a Camera and then updates the Pointers `worldX` and `worldY` values based on the cameras transform (thanks @Nick-lab)
9091

9192
### Updates
9293

src/input/Pointer.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,40 @@ var Pointer = new Class({
486486
this.deltaZ = 0;
487487
},
488488

489+
/**
490+
* Takes a Camera and updates this Pointer's `worldX` and `worldY` values so they are
491+
* the result of a translation through the given Camera.
492+
*
493+
* Note that the values will be automatically replaced the moment the Pointer is
494+
* updated by an input event, such as a mouse move, so should be used immediately.
495+
*
496+
* @method Phaser.Input.Pointer#updateWorldPoint
497+
* @since 3.19.0
498+
*
499+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera which is being tested against.
500+
*
501+
* @return {this} This Pointer object.
502+
*/
503+
updateWorldPoint: function (camera)
504+
{
505+
var x = this.x;
506+
var y = this.y;
507+
508+
if (camera.resolution !== 1)
509+
{
510+
x += camera._x;
511+
y += camera._y;
512+
}
513+
514+
// Stores the world point inside of tempPoint
515+
var temp = camera.getWorldPoint(x, y);
516+
517+
this.worldX = temp.x;
518+
this.worldY = temp.y;
519+
520+
return this;
521+
},
522+
489523
/**
490524
* Takes a Camera and returns a Vector2 containing the translated position of this Pointer
491525
* within that Camera. This can be used to convert this Pointers position into camera space.

0 commit comments

Comments
 (0)