Skip to content

Commit 756072b

Browse files
authored
Merge pull request phaserjs#4159 from jan1za/master
Added RotateTo Effect to Camera
2 parents 43723e6 + b3f847d commit 756072b

3 files changed

Lines changed: 454 additions & 0 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ var Camera = new Class({
117117
*/
118118
this.panEffect = new Effects.Pan(this);
119119

120+
/**
121+
* The Camera Rotate To effect handler.
122+
* To rotate this camera see the `Camera.rotateTo` method.
123+
*
124+
* @name Phaser.Cameras.Scene2D.Camera#rotateToEffect
125+
* @type {Phaser.Cameras.Scene2D.Effects.RotateTo}
126+
* @since 3.16.0
127+
*/
128+
this.rotateToEffect = new Effects.RotateTo(this);
129+
120130
/**
121131
* The Camera Zoom effect handler.
122132
* To zoom this camera see the `Camera.zoom` method.
@@ -684,6 +694,30 @@ var Camera = new Class({
684694
return this.panEffect.start(x, y, duration, ease, force, callback, context);
685695
},
686696

697+
/**
698+
* This effect will rotate the Camera so that the viewport finishes at the given angle in radians,
699+
* over the duration and with the ease specified.
700+
*
701+
* @method Phaser.Cameras.Scene2D.Camera#rotateTo
702+
* @since 3.16.0
703+
*
704+
* @param {number} radians - The destination angle in radians to rotate the Camera viewport to. If the angle is positive then the rotation is clockwise else anticlockwise
705+
* @param {boolean} [shortestPath=false] - If shortest path is set to true the camera will rotate in the quickest direction clockwise or anti-clockwise.
706+
* @param {integer} [duration=1000] - The duration of the effect in milliseconds.
707+
* @param {(string|function)} [ease='Linear'] - The ease to use for the rotation. Can be any of the Phaser Easing constants or a custom function.
708+
* @param {boolean} [force=false] - Force the rotation effect to start immediately, even if already running.
709+
* @param {CameraRotateCallback} [callback] - This callback will be invoked every frame for the duration of the effect.
710+
* It is sent four arguments: A reference to the camera, a progress amount between 0 and 1 indicating how complete the effect is,
711+
* the current camera rotation angle in radians.
712+
* @param {any} [context] - The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.
713+
*
714+
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
715+
*/
716+
rotateTo: function (radians, shortestPath, duration, ease, force, callback, context)
717+
{
718+
return this.rotateToEffect.start(radians, shortestPath, duration, ease, force, callback, context);
719+
},
720+
687721
/**
688722
* This effect will zoom the Camera to the given scale, over the duration and with the ease specified.
689723
*
@@ -954,6 +988,7 @@ var Camera = new Class({
954988
*/
955989
resetFX: function ()
956990
{
991+
this.rotateToEffect.reset();
957992
this.panEffect.reset();
958993
this.shakeEffect.reset();
959994
this.flashEffect.reset();
@@ -976,6 +1011,7 @@ var Camera = new Class({
9761011
{
9771012
if (this.visible)
9781013
{
1014+
this.rotateToEffect.update(time, delta);
9791015
this.panEffect.update(time, delta);
9801016
this.zoomEffect.update(time, delta);
9811017
this.shakeEffect.update(time, delta);

0 commit comments

Comments
 (0)