From e73cf7a7d32a1cba337dffc88095a8e615f4b144 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 12 Feb 2017 13:21:27 +0000 Subject: [PATCH] Tidying up. --- v3/src/camera/Camera-2.js | 195 ---------------------- v3/src/camera/Camera.js | 225 ++++++++++++++++++++------ v3/src/checksum.js | 2 +- v3/src/state/systems/CameraManager.js | 2 +- 4 files changed, 174 insertions(+), 250 deletions(-) delete mode 100644 v3/src/camera/Camera-2.js diff --git a/v3/src/camera/Camera-2.js b/v3/src/camera/Camera-2.js deleted file mode 100644 index 98879d2ee..000000000 --- a/v3/src/camera/Camera-2.js +++ /dev/null @@ -1,195 +0,0 @@ -var Transform = require('../components/experimental-Transform-2'); - -var Camera = function (x, y, width, height) -{ - this.x = x; - this.y = y; - this.width = width; - this.height = height; - - this.state = null; - this.statePositionX = 0.0; - this.statePositionY = 0.0; - this.scrollX = 0.0; - this.scrollY = 0.0; - this.zoom = 1.0; - this.rotation = 0.0; - - // shake - this._shakeDuration = 0.0; - this._shakeIntensity = 0.0; - this._shakeOffsetX = 0.0; - this._shakeOffsetY = 0.0; - - // fade - this._fadeDuration = 0.0; - this._fadeRed = 0.0; - this._fadeGreen = 0.0; - this._fadeBlue = 0.0; - this._fadeAlpha = 0.0; - - // flash - this._flashDuration = 0.0; - this._flashRed = 1.0; - this._flashGreen = 1.0; - this._flashBlue = 1.0; - this._flashAlpha = 0.0; -}; - -Camera.prototype.constructor = Camera; - -Camera.prototype = { - - setViewport: function (x, y, width, height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - }, - - setSize: function (width, height) - { - this.width = width; - this.height = height; - }, - - setState: function (state) - { - this.state = state; - }, - - update: function (delta) - { - if (this._flashAlpha > 0.0) - { - this._flashAlpha -= delta / this._flashDuration; - - if (this._flashAlpha < 0.0) - { - this._flashAlpha = 0.0; - } - } - - if (this._fadeAlpha > 0.0 && this._fadeAlpha < 1.0) - { - this._fadeAlpha += delta / this._fadeDuration; - - if (this._fadeAlpha >= 1.0) - { - this._fadeAlpha = 1.0; - } - } - - if (this._shakeDuration > 0.0) - { - var intensity = this._shakeIntensity; - - this._shakeDuration -= delta; - - if (this._shakeDuration <= 0.0) - { - this._shakeOffsetX = 0.0; - this._shakeOffsetY = 0.0; - } - else - { - this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom; - this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom; - } - } - }, - - flash: function (duration, red, green, blue, force) - { - if (!force && this._flashAlpha > 0.0) - { - return; - } - - if (red === undefined) { red = 1.0; } - if (green === undefined) { green = 1.0; } - if (blue === undefined) { blue = 1.0; } - - this._flashRed = red; - this._flashGreen = green; - this._flashBlue = blue; - - if (duration <= 0) - { - duration = Number.MIN_VALUE; - } - - this._flashDuration = duration; - this._flashAlpha = 1.0; - }, - - fade: function (duration, red, green, blue, force) - { - if (red === undefined) { red = 0.0; } - if (green === undefined) { green = 0.0; } - if (blue === undefined) { blue = 0.0; } - - if (!force && this._fadeAlpha > 0.0) - { - return; - } - - this._fadeRed = red; - this._fadeGreen = green; - this._fadeBlue = blue; - - if (duration <= 0) - { - duration = Number.MIN_VALUE; - } - - this._fadeDuration = duration; - this._fadeAlpha = Number.MIN_VALUE; - }, - - shake: function (duration, intensity, force) - { - if (intensity === undefined) { intensity = 0.05; } - - if (!force && (this._shakeOffsetX !== 0.0 || this._shakeOffsetY !== 0.0)) - { - return; - } - - this._shakeDuration = duration; - this._shakeIntensity = intensity; - this._shakeOffsetX = 0; - this._shakeOffsetY = 0; - }, - - preRender: function (interpolation, renderer) - { - var state = this.state; - var stateTransform = state.sys.transform; - - this.statePositionX = stateTransform.positionX; - this.statePositionY = stateTransform.positionY; - - stateTransform.positionX = this.statePositionX + this.x; - stateTransform.positionY = this.statePositionY + this.y; - - Transform.updateRoot(stateTransform, -this.scrollX + this._shakeOffsetX, -this.scrollY + this._shakeOffsetY, this.zoom, this.rotation); - }, - - postRender: function () - { - var stateTransform = this.state.sys.transform; - - stateTransform.positionX = this.statePositionX; - stateTransform.positionY = this.statePositionY; - }, - - destroy: function () - { - this.state = undefined; - } - -}; - -module.exports = Camera; diff --git a/v3/src/camera/Camera.js b/v3/src/camera/Camera.js index 92127e138..98879d2ee 100644 --- a/v3/src/camera/Camera.js +++ b/v3/src/camera/Camera.js @@ -1,76 +1,195 @@ +var Transform = require('../components/experimental-Transform-2'); -var BaseTransform = require('../components/BaseTransform'); - -/** -* A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. -* The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y -* -* @class Phaser.Camera -* @constructor -* @param {Phaser.Game} game - Game reference to the currently running game. -* @param {number} id - Not being used at the moment, will be when Phaser supports multiple camera -* @param {number} x - Position of the camera on the X axis -* @param {number} y - Position of the camera on the Y axis -* @param {number} width - The width of the view rectangle -* @param {number} height - The height of the view rectangle -*/ -var Camera = function (state, x, y, viewportWidth, viewportHeight) +var Camera = function (x, y, width, height) { - console.log('Camera', viewportWidth, viewportHeight); + this.x = x; + this.y = y; + this.width = width; + this.height = height; - this.state = state; + this.state = null; + this.statePositionX = 0.0; + this.statePositionY = 0.0; + this.scrollX = 0.0; + this.scrollY = 0.0; + this.zoom = 1.0; + this.rotation = 0.0; - BaseTransform.call(this, this, x, y); + // shake + this._shakeDuration = 0.0; + this._shakeIntensity = 0.0; + this._shakeOffsetX = 0.0; + this._shakeOffsetY = 0.0; - this.viewportWidth = viewportWidth; - this.viewportHeight = viewportHeight; + // fade + this._fadeDuration = 0.0; + this._fadeRed = 0.0; + this._fadeGreen = 0.0; + this._fadeBlue = 0.0; + this._fadeAlpha = 0.0; - this.transform.deleteTreeNode(); + // flash + this._flashDuration = 0.0; + this._flashRed = 1.0; + this._flashGreen = 1.0; + this._flashBlue = 1.0; + this._flashAlpha = 0.0; }; -Camera.prototype = Object.create(BaseTransform.prototype); Camera.prototype.constructor = Camera; -Camera.prototype.render = function () -{ -}; - -Object.defineProperties(Camera.prototype, { - - right: { - - enumerable: true, - - get: function () - { - return this.transform._posX + this.viewportWidth; - }, - - set: function (value) - { - this.transform._posX = value - this.viewportWidth; - this.transform.dirty = true; - } +Camera.prototype = { + setViewport: function (x, y, width, height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; }, - bottom: { + setSize: function (width, height) + { + this.width = width; + this.height = height; + }, - enumerable: true, + setState: function (state) + { + this.state = state; + }, - get: function () + update: function (delta) + { + if (this._flashAlpha > 0.0) { - return this.transform._posY + this.viewportHeight; - }, + this._flashAlpha -= delta / this._flashDuration; - set: function (value) - { - this.transform._posY = value - this.viewportHeight; - this.transform.dirty = true; + if (this._flashAlpha < 0.0) + { + this._flashAlpha = 0.0; + } } + if (this._fadeAlpha > 0.0 && this._fadeAlpha < 1.0) + { + this._fadeAlpha += delta / this._fadeDuration; + + if (this._fadeAlpha >= 1.0) + { + this._fadeAlpha = 1.0; + } + } + + if (this._shakeDuration > 0.0) + { + var intensity = this._shakeIntensity; + + this._shakeDuration -= delta; + + if (this._shakeDuration <= 0.0) + { + this._shakeOffsetX = 0.0; + this._shakeOffsetY = 0.0; + } + else + { + this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom; + this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom; + } + } + }, + + flash: function (duration, red, green, blue, force) + { + if (!force && this._flashAlpha > 0.0) + { + return; + } + + if (red === undefined) { red = 1.0; } + if (green === undefined) { green = 1.0; } + if (blue === undefined) { blue = 1.0; } + + this._flashRed = red; + this._flashGreen = green; + this._flashBlue = blue; + + if (duration <= 0) + { + duration = Number.MIN_VALUE; + } + + this._flashDuration = duration; + this._flashAlpha = 1.0; + }, + + fade: function (duration, red, green, blue, force) + { + if (red === undefined) { red = 0.0; } + if (green === undefined) { green = 0.0; } + if (blue === undefined) { blue = 0.0; } + + if (!force && this._fadeAlpha > 0.0) + { + return; + } + + this._fadeRed = red; + this._fadeGreen = green; + this._fadeBlue = blue; + + if (duration <= 0) + { + duration = Number.MIN_VALUE; + } + + this._fadeDuration = duration; + this._fadeAlpha = Number.MIN_VALUE; + }, + + shake: function (duration, intensity, force) + { + if (intensity === undefined) { intensity = 0.05; } + + if (!force && (this._shakeOffsetX !== 0.0 || this._shakeOffsetY !== 0.0)) + { + return; + } + + this._shakeDuration = duration; + this._shakeIntensity = intensity; + this._shakeOffsetX = 0; + this._shakeOffsetY = 0; + }, + + preRender: function (interpolation, renderer) + { + var state = this.state; + var stateTransform = state.sys.transform; + + this.statePositionX = stateTransform.positionX; + this.statePositionY = stateTransform.positionY; + + stateTransform.positionX = this.statePositionX + this.x; + stateTransform.positionY = this.statePositionY + this.y; + + Transform.updateRoot(stateTransform, -this.scrollX + this._shakeOffsetX, -this.scrollY + this._shakeOffsetY, this.zoom, this.rotation); + }, + + postRender: function () + { + var stateTransform = this.state.sys.transform; + + stateTransform.positionX = this.statePositionX; + stateTransform.positionY = this.statePositionY; + }, + + destroy: function () + { + this.state = undefined; } -}); +}; module.exports = Camera; diff --git a/v3/src/checksum.js b/v3/src/checksum.js index d4c111440..942daf4b6 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '58fae360-f125-11e6-ae98-f5fa1f6f0efe' +build: '1d85fb70-f126-11e6-8882-1b7f7c76ea39' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/state/systems/CameraManager.js b/v3/src/state/systems/CameraManager.js index fa2e58790..d57fafce6 100644 --- a/v3/src/state/systems/CameraManager.js +++ b/v3/src/state/systems/CameraManager.js @@ -1,4 +1,4 @@ -var Camera = require('../../camera/Camera-2'); +var Camera = require('../../camera/Camera'); var CameraManager = function (state) {