You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -330,6 +330,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
330
330
* FrameData.destroy will nullify the local arrays used to contain Frame instances.
331
331
* 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)
332
332
* 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)
333
+
* 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)
Copy file name to clipboardExpand all lines: src/core/Camera.js
+26-7Lines changed: 26 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,17 @@ Phaser.Camera = function (game, id, x, y, width, height) {
97
97
*/
98
98
this.totalInView=0;
99
99
100
+
/**
101
+
* The linear interpolation value to use when following a target.
102
+
* The default values of 1 means the camera will instantly snap to the target coordinates.
103
+
* A lower value, such as 0.1 means the camera will more slowly track the target, giving
104
+
* a smooth transition. You can set the horizontal and vertical values independently, and also
105
+
* adjust this value in real-time during your game.
106
+
* @property {Phaser.Point} lerp
107
+
* @default
108
+
*/
109
+
this.lerp=Phaser.Point(1,1);
110
+
100
111
/**
101
112
* @property {Phaser.Point} _targetPosition - Internal point used to calculate target position
102
113
* @private
@@ -158,19 +169,27 @@ Phaser.Camera.prototype = {
158
169
159
170
/**
160
171
* Tell the camera which sprite to follow.
172
+
*
173
+
* You can set the follow type and a linear interpolation value.
174
+
* Use low lerp values (such as 0.1) to automatically smooth the camera motion.
161
175
*
162
176
* If you find you're getting a slight "jitter" effect when following a Sprite it's probably to do with sub-pixel rendering of the Sprite position.
163
177
* This can be disabled by setting `game.renderer.renderSession.roundPixels = true` to force full pixel rendering.
164
178
*
165
179
* @method Phaser.Camera#follow
166
180
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text} target - The object you want the camera to track. Set to null to not follow anything.
167
181
* @param {number} [style] - Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
182
+
* @param {float} [lerpX=1] - A value between 0 and 1. This value specifies the amount of linear interpolation to use when horizontally tracking the target. The closer the value to 1, the faster the camera will track.
183
+
* @param {float} [lerpY=1] - A value between 0 and 1. This value specifies the amount of linear interpolation to use when vertically tracking the target. The closer the value to 1, the faster the camera will track.
0 commit comments