2013-08-06 02:43:53 +00:00
|
|
|
var __extends = this.__extends || function (d, b) {
|
2013-08-09 04:08:54 +00:00
|
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
2013-08-06 02:43:53 +00:00
|
|
|
function __() { this.constructor = d; }
|
|
|
|
__.prototype = b.prototype;
|
|
|
|
d.prototype = new __();
|
|
|
|
};
|
|
|
|
var Phaser;
|
|
|
|
(function (Phaser) {
|
|
|
|
(function (Plugins) {
|
|
|
|
/// <reference path="../../Phaser/Game.ts" />
|
|
|
|
/// <reference path="../../Phaser/core/Plugin.ts" />
|
|
|
|
/**
|
|
|
|
* Phaser - Plugins - Camera FX - Shake
|
|
|
|
*
|
|
|
|
* A simple camera shake effect.
|
|
|
|
*/
|
|
|
|
(function (CameraFX) {
|
|
|
|
var Shake = (function (_super) {
|
|
|
|
__extends(Shake, _super);
|
|
|
|
function Shake(game, parent) {
|
2013-08-09 04:08:54 +00:00
|
|
|
_super.call(this, game, parent);
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeIntensity = 0;
|
|
|
|
this._fxShakeDuration = 0;
|
|
|
|
this._fxShakeComplete = null;
|
|
|
|
this._fxShakeOffset = new Phaser.Point(0, 0);
|
|
|
|
this._fxShakeDirection = 0;
|
|
|
|
this._fxShakePrevX = 0;
|
|
|
|
this._fxShakePrevY = 0;
|
|
|
|
this.camera = parent;
|
|
|
|
}
|
2013-08-09 04:08:54 +00:00
|
|
|
/**
|
2013-08-06 02:43:53 +00:00
|
|
|
* A simple camera shake effect.
|
|
|
|
*
|
|
|
|
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
|
|
|
|
* @param Duration The length in seconds that the shaking effect should last.
|
|
|
|
* @param OnComplete A function you want to run when the shake effect finishes.
|
|
|
|
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
|
|
|
|
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
|
|
|
|
*/
|
2013-08-09 04:08:54 +00:00
|
|
|
Shake.prototype.start = function (intensity, duration, onComplete, force, direction) {
|
2013-08-06 02:43:53 +00:00
|
|
|
if (typeof intensity === "undefined") { intensity = 0.05; }
|
|
|
|
if (typeof duration === "undefined") { duration = 0.5; }
|
|
|
|
if (typeof onComplete === "undefined") { onComplete = null; }
|
|
|
|
if (typeof force === "undefined") { force = true; }
|
|
|
|
if (typeof direction === "undefined") { direction = Shake.SHAKE_BOTH_AXES; }
|
2013-08-09 04:08:54 +00:00
|
|
|
if (!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))) {
|
2013-08-06 02:43:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-09 04:08:54 +00:00
|
|
|
|
|
|
|
if (this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakePrevX = this.camera.x;
|
|
|
|
this._fxShakePrevY = this.camera.y;
|
|
|
|
}
|
2013-08-09 04:08:54 +00:00
|
|
|
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeIntensity = intensity;
|
|
|
|
this._fxShakeDuration = duration;
|
|
|
|
this._fxShakeComplete = onComplete;
|
|
|
|
this._fxShakeDirection = direction;
|
|
|
|
this._fxShakeOffset.setTo(0, 0);
|
|
|
|
};
|
2013-08-09 04:08:54 +00:00
|
|
|
|
2013-08-06 02:43:53 +00:00
|
|
|
Shake.prototype.postUpdate = function () {
|
2013-08-09 04:08:54 +00:00
|
|
|
if (this._fxShakeDuration > 0) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeDuration -= this.game.time.elapsed;
|
2013-08-09 04:08:54 +00:00
|
|
|
|
|
|
|
if (this.game.math.roundTo(this._fxShakeDuration, -2) <= 0) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeDuration = 0;
|
|
|
|
this._fxShakeOffset.setTo(0, 0);
|
|
|
|
this.camera.x = this._fxShakePrevX;
|
|
|
|
this.camera.y = this._fxShakePrevY;
|
2013-08-09 04:08:54 +00:00
|
|
|
|
|
|
|
if (this._fxShakeComplete != null) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeComplete();
|
|
|
|
}
|
|
|
|
} else {
|
2013-08-09 04:08:54 +00:00
|
|
|
if ((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_HORIZONTAL_ONLY)) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeOffset.x = (this.game.rnd.integer * this._fxShakeIntensity * this.camera.worldView.width * 2 - this._fxShakeIntensity * this.camera.worldView.width);
|
|
|
|
}
|
2013-08-09 04:08:54 +00:00
|
|
|
|
|
|
|
if ((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_VERTICAL_ONLY)) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this._fxShakeOffset.y = (this.game.rnd.integer * this._fxShakeIntensity * this.camera.worldView.height * 2 - this._fxShakeIntensity * this.camera.worldView.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-08-09 04:08:54 +00:00
|
|
|
|
2013-08-06 02:43:53 +00:00
|
|
|
Shake.prototype.preRender = function () {
|
2013-08-09 04:08:54 +00:00
|
|
|
if ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0)) {
|
2013-08-06 02:43:53 +00:00
|
|
|
this.camera.x = this._fxShakePrevX + this._fxShakeOffset.x;
|
|
|
|
this.camera.y = this._fxShakePrevY + this._fxShakeOffset.y;
|
|
|
|
}
|
|
|
|
};
|
2013-08-09 04:08:54 +00:00
|
|
|
Shake.SHAKE_BOTH_AXES = 0;
|
|
|
|
Shake.SHAKE_HORIZONTAL_ONLY = 1;
|
|
|
|
Shake.SHAKE_VERTICAL_ONLY = 2;
|
2013-08-06 02:43:53 +00:00
|
|
|
return Shake;
|
|
|
|
})(Phaser.Plugin);
|
2013-08-09 04:08:54 +00:00
|
|
|
CameraFX.Shake = Shake;
|
2013-08-06 02:43:53 +00:00
|
|
|
})(Plugins.CameraFX || (Plugins.CameraFX = {}));
|
|
|
|
var CameraFX = Plugins.CameraFX;
|
|
|
|
})(Phaser.Plugins || (Phaser.Plugins = {}));
|
|
|
|
var Plugins = Phaser.Plugins;
|
|
|
|
})(Phaser || (Phaser = {}));
|