|
6 | 6 |
|
7 | 7 | var MATH_CONST = require('../../math/const'); |
8 | 8 | var TransformMatrix = require('./TransformMatrix'); |
| 9 | +var TransformXY = require('../../math/TransformXY'); |
9 | 10 | var WrapAngle = require('../../math/angle/Wrap'); |
10 | 11 | var WrapAngleDegrees = require('../../math/angle/WrapDegrees'); |
| 12 | +var Vector2 = require('../../math/Vector2'); |
11 | 13 |
|
12 | 14 | // global bitmask flag for GameObject.renderMask (used by Scale) |
13 | 15 | var _FLAG = 4; // 0100 |
@@ -502,6 +504,56 @@ var Transform = { |
502 | 504 | return tempMatrix; |
503 | 505 | }, |
504 | 506 |
|
| 507 | + /** |
| 508 | + * Takes the given `x` and `y` coordinates and converts them into local space for this |
| 509 | + * Game Object, taking into account parent and local transforms, and the Display Origin. |
| 510 | + * |
| 511 | + * The returned Vector2 contains the translated point in its properties. |
| 512 | + * |
| 513 | + * A Camera needs to be provided in order to handle modified scroll factors. If no |
| 514 | + * camera is specified, it will use the `main` camera from the Scene to which this |
| 515 | + * Game Object belongs. |
| 516 | + * |
| 517 | + * @method Phaser.GameObjects.Components.Transform#getLocalPoint |
| 518 | + * @since 3.50.0 |
| 519 | + * |
| 520 | + * @param {number} x - The x position to translate. |
| 521 | + * @param {number} y - The y position to translate. |
| 522 | + * @param {Phaser.Math.Vector2} [point] - A Vector2, or point-like object, to store the results in. |
| 523 | + * @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera which is being tested against. If not given will use the Scene default camera. |
| 524 | + * |
| 525 | + * @return {Phaser.Math.Vector2} The translated point. |
| 526 | + */ |
| 527 | + getLocalPoint: function (x, y, point, camera) |
| 528 | + { |
| 529 | + if (!point) { point = new Vector2(); } |
| 530 | + if (!camera) { camera = this.scene.sys.cameras.main; } |
| 531 | + |
| 532 | + var csx = camera.scrollX; |
| 533 | + var csy = camera.scrollY; |
| 534 | + |
| 535 | + var px = x + (csx * this.scrollFactorX) - csx; |
| 536 | + var py = y + (csy * this.scrollFactorY) - csy; |
| 537 | + |
| 538 | + if (this.parentContainer) |
| 539 | + { |
| 540 | + this.getWorldTransformMatrix().applyInverse(px, py, point); |
| 541 | + } |
| 542 | + else |
| 543 | + { |
| 544 | + TransformXY(px, py, this.x, this.y, this.rotation, this.scaleX, this.scaleY, point); |
| 545 | + } |
| 546 | + |
| 547 | + // Normalize origin |
| 548 | + if (this._originComponent) |
| 549 | + { |
| 550 | + point.x += this._displayOriginX; |
| 551 | + point.y += this._displayOriginY; |
| 552 | + } |
| 553 | + |
| 554 | + return point; |
| 555 | + }, |
| 556 | + |
505 | 557 | /** |
506 | 558 | * Gets the sum total rotation of all of this Game Objects parent Containers. |
507 | 559 | * |
|
0 commit comments