mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
Tidying up.
This commit is contained in:
parent
0975752463
commit
e73cf7a7d3
4 changed files with 174 additions and 250 deletions
|
@ -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;
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '58fae360-f125-11e6-ae98-f5fa1f6f0efe'
|
||||
build: '1d85fb70-f126-11e6-8882-1b7f7c76ea39'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -1,4 +1,4 @@
|
|||
var Camera = require('../../camera/Camera-2');
|
||||
var Camera = require('../../camera/Camera');
|
||||
|
||||
var CameraManager = function (state)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue