2015-03-01 07:00:17 +00:00
|
|
|
/**
|
|
|
|
* FixedToCamera Component Features.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-02-17 05:15:04 +00:00
|
|
|
Phaser.Component.FixedToCamera = function () {};
|
|
|
|
|
|
|
|
Phaser.Component.FixedToCamera.postUpdate = function () {
|
|
|
|
|
|
|
|
if (this.fixedToCamera)
|
|
|
|
{
|
|
|
|
this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
|
|
|
|
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Component.FixedToCamera.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Sprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Sprite.cameraOffset.
|
|
|
|
* Note that the cameraOffset values are in addition to any parent in the display list.
|
|
|
|
* So if this Sprite was in a Group that has x: 200, then this will be added to the cameraOffset.x
|
2015-03-01 07:00:17 +00:00
|
|
|
*
|
2015-02-18 22:58:48 +00:00
|
|
|
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have fixedToCamera enabled on them.
|
2015-03-01 07:00:17 +00:00
|
|
|
*
|
2015-02-17 05:15:04 +00:00
|
|
|
* @property {boolean} fixedToCamera
|
|
|
|
*/
|
|
|
|
fixedToCamera: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} cameraOffset - If this object is fixedToCamera then this stores the x/y offset that it is drawn at. Values are relative to the top-left of the camera view.
|
|
|
|
*/
|
2015-02-17 05:59:54 +00:00
|
|
|
cameraOffset: new Phaser.Point()
|
2015-02-17 05:15:04 +00:00
|
|
|
|
|
|
|
};
|