Skip to content

Commit 50179d7

Browse files
committed
Merge pull request phaserjs#1015 from Zielak/dev
Phaser.Camera.position for quick access
2 parents ee579c2 + 64ae6c6 commit 50179d7

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/core/Camera.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ Phaser.Camera = function (game, id, x, y, width, height) {
8686
*/
8787
this._edge = 0;
8888

89+
/**
90+
* @property {Phaser.Point} position - Current position of the camera in world.
91+
* @private
92+
* @default
93+
*/
94+
this._position = new Phaser.Point();
95+
8996
/**
9097
* @property {PIXI.DisplayObject} displayObject - The display object to which all game objects are added. Set by World.boot
9198
*/
@@ -406,6 +413,31 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
406413

407414
});
408415

416+
/**
417+
* The Cameras position. This value is automatically clamped if it falls outside of the World bounds.
418+
* @name Phaser.Camera#position
419+
* @property {Phaser.Point} position - Gets or sets the cameras xy position using Phaser.Point object.
420+
*/
421+
Object.defineProperty(Phaser.Camera.prototype, "position", {
422+
423+
get: function () {
424+
this._position.set(this.view.centerX, this.view.centerY);
425+
return this._position;
426+
},
427+
428+
set: function (value) {
429+
430+
if (typeof value.x !== "undefined") { this.view.x = value.x; }
431+
if (typeof value.y !== "undefined") { this.view.y = value.y; }
432+
433+
if (this.bounds)
434+
{
435+
this.checkBounds();
436+
}
437+
}
438+
439+
});
440+
409441
/**
410442
* The Cameras width. By default this is the same as the Game size and should not be adjusted for now.
411443
* @name Phaser.Camera#width

0 commit comments

Comments
 (0)