mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
Camera.shake is a new function that creates a camera shake effect. You can specify the intensity, duration and direction of the effect. You can also set if it should shake the camera out of bounds or not.
This commit is contained in:
parent
0b0a5d44cc
commit
2ea94c83e6
3 changed files with 46 additions and 5 deletions
|
@ -331,6 +331,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
|||
* SoundManager.muteOnPause is a new boolean that allows you to control if the Sound system gets muted automatically when a Phaser game pauses, such as when it loses focus. You may need to set this to `false` if you wish to control the audio system from outside of your Phaser game, i.e. from DOM buttons or similar (#2382)
|
||||
* You can now pass a TilemapLayer as a Texture to a TileSprite. A limitation of this is that if you pass it to a TileSprite it will make a fill pattern from the TilemapLayer at that instant it's passed, and it won't keep track of the layer in future should it update (thanks @jdnichollsc #1989)
|
||||
* Camera has a new property: `lerp`. This is a Point object, that allows you to control the amount of horizontal and vertical smoothing to be applied to the camera when it tracks a Sprite. It works both with and without deadzones, and is turned off by default. Set it to low values such as 0.1 for really smooth motion tracking (thanks to @WombatTurkey for the idea of adding this)
|
||||
* Camera.shake is a new function that creates a camera shake effect. You can specify the intensity, duration and direction of the effect. You can also set if it should shake the camera out of bounds or not.
|
||||
|
||||
### New Arcade Physics Features
|
||||
|
||||
|
|
|
@ -108,6 +108,11 @@ Phaser.Camera = function (game, id, x, y, width, height) {
|
|||
*/
|
||||
this.lerp = new Phaser.Point(1, 1);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} shakeOnComplete - This signal is dispatched when the camera shake effect completes.
|
||||
*/
|
||||
this.shakeOnComplete = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} _targetPosition - Internal point used to calculate target position.
|
||||
* @private
|
||||
|
@ -128,6 +133,10 @@ Phaser.Camera = function (game, id, x, y, width, height) {
|
|||
*/
|
||||
this._position = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Object} _shake - The shake effect container.
|
||||
* @private
|
||||
*/
|
||||
this._shake = {
|
||||
intensity: 0,
|
||||
duration: 0,
|
||||
|
@ -138,8 +147,6 @@ Phaser.Camera = function (game, id, x, y, width, height) {
|
|||
y: 0
|
||||
};
|
||||
|
||||
this.shakeOnComplete = new Phaser.Signal();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -299,6 +306,7 @@ Phaser.Camera.prototype = {
|
|||
* @param {boolean} [force=true] - If a camera shake effect is already running and force is true it will replace the previous effect, resetting the duration.
|
||||
* @param {number} [direction=Phaser.Camera.SHAKE_BOTH] - The directions in which the camera can shake. Either Phaser.Camera.SHAKE_BOTH, Phaser.Camera.SHAKE_HORIZONTAL or Phaser.Camera.SHAKE_VERTICAL.
|
||||
* @param {boolean} [shakeBounds=true] - Is the effect allowed to shake the camera beyond its bounds (if set?).
|
||||
* @return {boolean} True if the shake effect was started, otherwise false.
|
||||
*/
|
||||
shake: function (intensity, duration, force, direction, shakeBounds) {
|
||||
|
||||
|
@ -311,7 +319,7 @@ Phaser.Camera.prototype = {
|
|||
if (!force && this._shake.duration > 0)
|
||||
{
|
||||
// Can't reset an already running shake
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
this._shake.intensity = intensity;
|
||||
|
@ -324,11 +332,15 @@ Phaser.Camera.prototype = {
|
|||
this._shake.horizontal = (direction === Phaser.Camera.SHAKE_BOTH || direction === Phaser.Camera.SHAKE_HORIZONTAL);
|
||||
this._shake.vertical = (direction === Phaser.Camera.SHAKE_BOTH || direction === Phaser.Camera.SHAKE_VERTICAL);
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update focusing and scrolling.
|
||||
* The camera update loop. This is called automatically by the core game loop.
|
||||
*
|
||||
* @method Phaser.Camera#update
|
||||
* @protected
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
|
@ -359,6 +371,12 @@ Phaser.Camera.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the camera shake effect.
|
||||
*
|
||||
* @method Phaser.Camera#updateShake
|
||||
* @private
|
||||
*/
|
||||
updateShake: function () {
|
||||
|
||||
this._shake.duration -= this.game.time.elapsedMS;
|
||||
|
@ -385,7 +403,8 @@ Phaser.Camera.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Internal method
|
||||
* Internal method that handles tracking a sprite.
|
||||
*
|
||||
* @method Phaser.Camera#updateTarget
|
||||
* @private
|
||||
*/
|
||||
|
@ -427,6 +446,7 @@ Phaser.Camera.prototype = {
|
|||
|
||||
/**
|
||||
* Update the Camera bounds to match the game world.
|
||||
*
|
||||
* @method Phaser.Camera#setBoundsToWorld
|
||||
*/
|
||||
setBoundsToWorld: function () {
|
||||
|
@ -440,7 +460,10 @@ Phaser.Camera.prototype = {
|
|||
|
||||
/**
|
||||
* Method called to ensure the camera doesn't venture outside of the game world.
|
||||
* Called automatically by Camera.update.
|
||||
*
|
||||
* @method Phaser.Camera#checkBounds
|
||||
* @protected
|
||||
*/
|
||||
checkBounds: function () {
|
||||
|
||||
|
@ -562,7 +585,9 @@ Phaser.Camera.prototype.constructor = Phaser.Camera;
|
|||
Object.defineProperty(Phaser.Camera.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.x;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
@ -585,7 +610,9 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
|
|||
Object.defineProperty(Phaser.Camera.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.y;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
@ -608,8 +635,11 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
|
|||
Object.defineProperty(Phaser.Camera.prototype, "position", {
|
||||
|
||||
get: function () {
|
||||
|
||||
this._position.set(this.view.x, this.view.y);
|
||||
|
||||
return this._position;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
@ -633,11 +663,15 @@ Object.defineProperty(Phaser.Camera.prototype, "position", {
|
|||
Object.defineProperty(Phaser.Camera.prototype, "width", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.width;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.view.width = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -650,11 +684,15 @@ Object.defineProperty(Phaser.Camera.prototype, "width", {
|
|||
Object.defineProperty(Phaser.Camera.prototype, "height", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.view.height;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.view.height = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
2
typescript/phaser.d.ts
vendored
2
typescript/phaser.d.ts
vendored
|
@ -595,6 +595,7 @@ declare module Phaser {
|
|||
position: Phaser.Point;
|
||||
roundPx: boolean;
|
||||
scale: Phaser.Point;
|
||||
shakeOnComplete: Phaser.Signal;
|
||||
target: Phaser.Sprite;
|
||||
totalInView: number;
|
||||
view: Phaser.Rectangle;
|
||||
|
@ -612,6 +613,7 @@ declare module Phaser {
|
|||
setBoundsToWorld(): void;
|
||||
setPosition(x: number, y: number): void;
|
||||
setSize(width: number, height: number): void;
|
||||
shake(intensity?: number, duration?: number, force?: boolean, direction?: number, shakeBounds?: boolean): boolean;
|
||||
unfollow(): void;
|
||||
update(): void;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue