2013-06-06 01:47:08 +00:00
|
|
|
/// <reference path="../Game.ts" />
|
2013-06-07 15:27:33 +00:00
|
|
|
/// <reference path="../geom/Point.ts" />
|
|
|
|
/// <reference path="../geom/Rectangle.ts" />
|
|
|
|
/// <reference path="../math/Vec2.ts" />
|
2013-05-28 20:38:37 +00:00
|
|
|
/// <reference path="../components/camera/CameraFX.ts" />
|
2013-06-06 01:47:08 +00:00
|
|
|
/// <reference path="../components/Texture.ts" />
|
|
|
|
/// <reference path="../components/Transform.ts" />
|
|
|
|
/// <reference path="../gameobjects/Sprite.ts" />
|
2013-04-18 13:16:18 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-18 15:49:08 +00:00
|
|
|
* Phaser - Camera
|
|
|
|
*
|
|
|
|
* A Camera is your view into the game world. It has a position, size, scale and rotation and renders only those objects
|
|
|
|
* within its field of view. The game automatically creates a single Stage sized camera on boot, but it can be changed and
|
|
|
|
* additional cameras created via the CameraManager.
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
module Phaser {
|
|
|
|
|
|
|
|
export class Camera {
|
|
|
|
|
|
|
|
/**
|
2013-05-04 12:02:12 +00:00
|
|
|
* Instantiates a new camera at the specified location, with the specified size and zoom level.
|
|
|
|
*
|
|
|
|
* @param game {Phaser.Game} Current game instance.
|
|
|
|
* @param id {number} Unique identity.
|
|
|
|
* @param x {number} X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
|
|
|
* @param y {number} Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
|
|
|
* @param width {number} The width of the camera display in pixels.
|
|
|
|
* @param height {number} The height of the camera display in pixels.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
constructor(game: Game, id: number, x: number, y: number, width: number, height: number) {
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.game = game;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
|
|
|
this.ID = id;
|
2013-06-06 01:47:08 +00:00
|
|
|
this.z = id;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
// The view into the world we wish to render (by default the full game world size)
|
|
|
|
// The size of this Rect is the same as screenView, but the values are all in world coordinates instead of screen coordinates
|
2013-04-18 13:16:18 +00:00
|
|
|
this.worldView = new Rectangle(0, 0, width, height);
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
// The rect of the area being rendered in stage/screen coordinates
|
|
|
|
this.screenView = new Rectangle(x, y, width, height);
|
|
|
|
|
|
|
|
this.fx = new CameraFX(this.game, this);
|
|
|
|
|
|
|
|
this.transform = new Phaser.Components.Transform(this);
|
|
|
|
this.texture = new Phaser.Components.Texture(this);
|
|
|
|
|
|
|
|
this.texture.opaque = false;
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.checkClip();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
private _target: Sprite = null;
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Local private reference to Game.
|
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public game: Game;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
/**
|
|
|
|
* Optional texture used in the background of the Camera.
|
|
|
|
*/
|
|
|
|
public texture: Phaser.Components.Texture;
|
2013-05-28 20:38:37 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
/**
|
|
|
|
* The transform component.
|
|
|
|
*/
|
|
|
|
public transform: Phaser.Components.Transform;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public static STYLE_LOCKON: number = 0;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Camera "follow" style preset: camera deadzone is narrow but tall.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public static STYLE_PLATFORMER: number = 1;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Camera "follow" style preset: camera deadzone is a medium-size square around the focus object.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public static STYLE_TOPDOWN: number = 2;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Camera "follow" style preset: camera deadzone is a small square around the focus object.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public static STYLE_TOPDOWN_TIGHT: number = 3;
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Identity of this camera.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public ID: number;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Controls if this camera is clipped or not when rendering. You shouldn't usually set this value directly.
|
|
|
|
*/
|
|
|
|
public clip: bool = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Camera view Rectangle in world coordinate.
|
2013-05-04 12:02:12 +00:00
|
|
|
* @type {Rectangle}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public worldView: Rectangle;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Visible / renderable area (changes if the camera resizes/moves around the stage)
|
|
|
|
* @type {Rectangle}
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public screenView: Rectangle;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Camera worldBounds.
|
|
|
|
* @type {Rectangle}
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public worldBounds: Rectangle = null;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* A boolean representing if the Camera has been modified in any way via a scale, rotate, flip or skew.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public modified: bool = false;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Sprite moving inside this Rectangle will not cause camera moving.
|
2013-05-04 12:02:12 +00:00
|
|
|
* @type {Rectangle}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public deadzone: Rectangle = null;
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-05-28 08:37:32 +00:00
|
|
|
* Disable the automatic camera canvas clipping when Camera is non-Stage sized.
|
|
|
|
* @type {Boolean}
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-05-28 08:37:32 +00:00
|
|
|
public disableClipping: bool = false;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Whether this camera is visible or not. (default is true)
|
2013-05-04 12:02:12 +00:00
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public visible: bool = true;
|
2013-05-14 02:37:38 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* The z value of this Camera. Cameras are rendered in z-index order by the Renderer.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public z: number = -1;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Effects manager.
|
2013-05-28 20:38:37 +00:00
|
|
|
* @type {CameraFX}
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-05-28 20:38:37 +00:00
|
|
|
public fx: CameraFX;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides an object from this Camera. Hidden objects are not rendered.
|
|
|
|
* The object must implement a public cameraBlacklist property.
|
|
|
|
*
|
|
|
|
* @param object {Sprite/Group} The object this camera should ignore.
|
|
|
|
*/
|
|
|
|
public hide(object) {
|
|
|
|
|
|
|
|
if (this.isHidden(object) == false)
|
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
object.texture['cameraBlacklist'].push(this.ID);
|
2013-05-28 20:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the object is hidden from this Camera.
|
|
|
|
*
|
|
|
|
* @param object {Sprite/Group} The object to check.
|
|
|
|
*/
|
|
|
|
public isHidden(object): bool {
|
2013-06-06 01:47:08 +00:00
|
|
|
return (object.texture['cameraBlacklist'] && object.texture['cameraBlacklist'].length > 0 && object.texture['cameraBlacklist'].indexOf(this.ID) == -1);
|
2013-05-28 20:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Un-hides an object previously hidden to this Camera.
|
|
|
|
* The object must implement a public cameraBlacklist property.
|
|
|
|
*
|
|
|
|
* @param object {Sprite/Group} The object this camera should display.
|
|
|
|
*/
|
|
|
|
public show(object) {
|
|
|
|
|
|
|
|
if (this.isHidden(object) == true)
|
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
object.texture['cameraBlacklist'].slice(object.texture['cameraBlacklist'].indexOf(this.ID), 1);
|
2013-05-28 20:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Tells this camera object what sprite to track.
|
|
|
|
* @param target {Sprite} The object you want the camera to track. Set to null to not follow anything.
|
2013-05-04 16:18:45 +00:00
|
|
|
* @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this._target = target;
|
2013-04-28 11:25:02 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
var helper: number;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
case Camera.STYLE_PLATFORMER:
|
|
|
|
var w: number = this.width / 8;
|
|
|
|
var h: number = this.height / 3;
|
|
|
|
this.deadzone = new Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
|
|
|
|
break;
|
|
|
|
case Camera.STYLE_TOPDOWN:
|
|
|
|
helper = Math.max(this.width, this.height) / 4;
|
|
|
|
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
|
|
|
break;
|
|
|
|
case Camera.STYLE_TOPDOWN_TIGHT:
|
|
|
|
helper = Math.max(this.width, this.height) / 8;
|
|
|
|
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
|
|
|
break;
|
|
|
|
case Camera.STYLE_LOCKON:
|
|
|
|
default:
|
|
|
|
this.deadzone = null;
|
|
|
|
break;
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Move the camera focus to this location instantly.
|
|
|
|
* @param x {number} X position.
|
|
|
|
* @param y {number} Y position.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public focusOnXY(x: number, y: number) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
x += (x > 0) ? 0.0000001 : -0.0000001;
|
|
|
|
y += (y > 0) ? 0.0000001 : -0.0000001;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = Math.round(x - this.worldView.halfWidth);
|
|
|
|
this.worldView.y = Math.round(y - this.worldView.halfHeight);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Move the camera focus to this location instantly.
|
|
|
|
* @param point {any} Point you want to focus.
|
|
|
|
*/
|
2013-04-28 13:59:44 +00:00
|
|
|
public focusOn(point) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
|
|
|
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
|
|
|
|
this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
|
|
|
* Specify the boundaries of the world or where the camera is allowed to move.
|
2013-05-04 12:02:12 +00:00
|
|
|
*
|
|
|
|
* @param x {number} The smallest X value of your world (usually 0).
|
|
|
|
* @param y {number} The smallest Y value of your world (usually 0).
|
|
|
|
* @param width {number} The largest X value of your world (usually the world width).
|
|
|
|
* @param height {number} The largest Y value of your world (usually the world height).
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
2013-04-25 00:55:56 +00:00
|
|
|
public setBounds(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldBounds == null)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldBounds = new Rectangle;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldBounds.setTo(x, y, width, height);
|
2013-04-28 13:59:44 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = x;
|
|
|
|
this.worldView.y = y;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.update();
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Update focusing and scrolling.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public update() {
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
|
|
|
|
{
|
|
|
|
this.modified = true;
|
|
|
|
}
|
|
|
|
|
2013-05-01 03:10:21 +00:00
|
|
|
this.fx.preUpdate();
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
if (this._target !== null)
|
|
|
|
{
|
|
|
|
if (this.deadzone == null)
|
|
|
|
{
|
2013-05-22 23:01:58 +00:00
|
|
|
this.focusOnXY(this._target.x, this._target.y);
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var edge: number;
|
|
|
|
var targetX: number = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
|
|
|
|
var targetY: number = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
|
|
|
|
|
|
|
|
edge = targetX - this.deadzone.x;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.x > edge)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = edge;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.x < edge)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = edge;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
edge = targetY - this.deadzone.y;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.y > edge)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.y = edge;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.y < edge)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.y = edge;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
// Make sure we didn't go outside the cameras worldBounds
|
|
|
|
if (this.worldBounds !== null)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.x < this.worldBounds.left)
|
2013-04-12 16:19:56 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = this.worldBounds.left;
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.x > this.worldBounds.right - this.width)
|
2013-04-12 16:19:56 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.x = (this.worldBounds.right - this.width) + 1;
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.y < this.worldBounds.top)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.y = this.worldBounds.top;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldView.y > this.worldBounds.bottom - this.height)
|
2013-04-12 16:19:56 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 06:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update focusing and scrolling.
|
|
|
|
*/
|
|
|
|
public postUpdate() {
|
|
|
|
|
|
|
|
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
|
|
|
|
{
|
|
|
|
this.modified = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we didn't go outside the cameras worldBounds
|
|
|
|
if (this.worldBounds !== null)
|
|
|
|
{
|
|
|
|
if (this.worldView.x < this.worldBounds.left)
|
|
|
|
{
|
|
|
|
this.worldView.x = this.worldBounds.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.worldView.x > this.worldBounds.right - this.width)
|
|
|
|
{
|
|
|
|
this.worldView.x = (this.worldBounds.right - this.width) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.worldView.y < this.worldBounds.top)
|
|
|
|
{
|
|
|
|
this.worldView.y = this.worldBounds.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.worldView.y > this.worldBounds.bottom - this.height)
|
|
|
|
{
|
|
|
|
this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-01 03:10:21 +00:00
|
|
|
this.fx.postUpdate();
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Render debug infos. (including id, position, rotation, scrolling factor, worldBounds and some other properties)
|
2013-05-04 12:02:12 +00:00
|
|
|
* @param x {number} X position of the debug info to be rendered.
|
|
|
|
* @param y {number} Y position of the debug info to be rendered.
|
2013-05-04 16:18:45 +00:00
|
|
|
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.game.stage.context.fillStyle = color;
|
|
|
|
this.game.stage.context.fillText('Camera ID: ' + this.ID + ' (' + this.screenView.width + ' x ' + this.screenView.height + ')', x, y);
|
|
|
|
this.game.stage.context.fillText('X: ' + this.screenView.x + ' Y: ' + this.screenView.y + ' rotation: ' + this.transform.rotation, x, y + 14);
|
2013-06-07 06:35:28 +00:00
|
|
|
this.game.stage.context.fillText('World X: ' + this.worldView.x + ' World Y: ' + this.worldView.y + ' W: ' + this.worldView.width + ' H: ' + this.worldView.height + ' R: ' + this.worldView.right + ' B: ' + this.worldView.bottom, x, y + 28);
|
|
|
|
this.game.stage.context.fillText('ScreenView X: ' + this.screenView.x + ' Y: ' + this.screenView.y + ' W: ' + this.screenView.width + ' H: ' + this.screenView.height, x, y + 42);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.worldBounds)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-07 06:35:28 +00:00
|
|
|
this.game.stage.context.fillText('Bounds: ' + this.worldBounds.width + ' x ' + this.worldBounds.height, x, y + 56);
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-28 20:38:37 +00:00
|
|
|
/**
|
|
|
|
* Destroys this camera, associated FX and removes itself from the CameraManager.
|
|
|
|
*/
|
|
|
|
public destroy() {
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.game.world.cameras.removeCamera(this.ID);
|
2013-05-28 20:38:37 +00:00
|
|
|
this.fx.destroy();
|
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
public get x(): number {
|
2013-06-06 01:47:08 +00:00
|
|
|
return this.worldView.x;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
public get y(): number {
|
|
|
|
return this.worldView.y;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
public set x(value: number) {
|
|
|
|
this.worldView.x = value;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
public set y(value: number) {
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.y = value;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
public get width(): number {
|
2013-06-06 01:47:08 +00:00
|
|
|
return this.screenView.width;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
public get height(): number {
|
|
|
|
return this.screenView.height;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
public set width(value: number) {
|
|
|
|
this.screenView.width = value;
|
|
|
|
this.worldView.width = value;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
public set height(value: number) {
|
2013-06-06 01:47:08 +00:00
|
|
|
this.screenView.height = value;
|
|
|
|
this.worldView.height = value;
|
|
|
|
}
|
2013-04-28 13:59:44 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
public setPosition(x: number, y: number) {
|
|
|
|
this.screenView.x = x;
|
|
|
|
this.screenView.y = y;
|
|
|
|
this.checkClip();
|
|
|
|
}
|
2013-04-28 13:59:44 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
public setSize(width: number, height: number) {
|
|
|
|
this.screenView.width = width * this.transform.scale.x;
|
|
|
|
this.screenView.height = height * this.transform.scale.y;
|
|
|
|
this.worldView.width = width;
|
|
|
|
this.worldView.height = height;
|
2013-04-18 13:16:18 +00:00
|
|
|
this.checkClip();
|
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
/**
|
|
|
|
* The angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public get rotation(): number {
|
2013-06-06 01:47:08 +00:00
|
|
|
return this.transform.rotation;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
/**
|
|
|
|
* Set the angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
|
|
|
* The value is automatically wrapped to be between 0 and 360.
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public set rotation(value: number) {
|
2013-06-06 01:47:08 +00:00
|
|
|
this.transform.rotation = this.game.math.wrap(value, 360, 0);
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
private checkClip() {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.screenView.x != 0 || this.screenView.y != 0 || this.screenView.width < this.game.stage.width || this.screenView.height < this.game.stage.height)
|
2013-04-18 13:16:18 +00:00
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.clip = true;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-06 01:47:08 +00:00
|
|
|
this.clip = false;
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|