Skip to content

Commit 587c3e5

Browse files
committed
Arcade.Body.friction allows you to have more fine-grained control over the amount of velocity passed between bodies on collision.
1 parent 6fb816a commit 587c3e5

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ Version 2.3.0 - "Tarabon" - in dev
6363
### New Features
6464

6565
* `Physics.Arcade.isPaused` allows you to toggle Arcade Physics processing on and off. If `true` the `Body.preUpdate` method will be skipped, halting all motion for all bodies. Note that other methods such as `collide` will still work, so be careful not to call them on paused bodies.
66+
* `Arcade.Body.friction` allows you to have more fine-grained control over the amount of velocity passed between bodies on collision.
6667

6768
### Updates
6869

69-
* TypeScript definitions fixes and updates (thanks @clark-stevenson @TimvdEijnden)
70+
* TypeScript definitions fixes and updates (thanks @clark-stevenson @TimvdEijnden @belohlavek @ivw)
7071

7172
### Bug Fixes
7273

@@ -122,13 +123,13 @@ Phaser is released under the [MIT License](http://opensource.org/licenses/MIT).
122123

123124
<img src="http://phaser.io/images/github/learn.jpg" align="right">
124125

125-
We have a [Getting Started Guide](http://phaser.io/getting-started-js.php) which covers all you need to begin developing games with Phaser. From setting up a web server to picking an IDE to coding your first game.
126+
We have a [Getting Started Guide](http://phaser.io/getting-started-js.php) which covers all you need to begin developing games with Phaser. From setting up a web server, to picking an IDE and coding your first game.
126127

127128
Prefer **videos** to reading? Lynda.com have published a free course: [HTML5 Game Development with Phaser](http://www.lynda.com/Phaser-tutorials/HTML5-Game-Development-Phaser/163641-2.html)
128129

129-
Use the [How to Learn Phaser](http://gamedevelopment.tutsplus.com/articles/how-to-learn-the-phaser-html5-game-engine--gamedev-13643) guide we wrote for GameDevTuts+. It covers finding tutorials, examples and getting support.
130+
Use the [How to Learn Phaser](http://gamedevelopment.tutsplus.com/articles/how-to-learn-the-phaser-html5-game-engine--gamedev-13643) guide we wrote for GameDevTuts. It covers finding tutorials, examples and getting support.
130131

131-
Although currently a bit of a "wall of text" we urge you to keep and eye on the **News** section of the [Phaser web site](http://phaser.io). We post fresh links posted there *daily*.
132+
Although currently a bit of a "wall of text" we urge you to keep an eye on the **News** section of the [Phaser web site](http://phaser.io). We post fresh links there *daily*.
132133

133134
Using Phaser with **TypeScript**? Check out this great series of [Game From Scratch](http://www.gamefromscratch.com/page/Adventures-in-Phaser-with-TypeScript-tutorial-series.aspx) tutorials.
134135

src/physics/arcade/Body.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
8787
this.width = sprite.width;
8888

8989
/**
90-
* @property .numInternal ID cache
90+
* @property {number} height - The calculated height of the physics body.
9191
*/
9292
this.height = sprite.height;
9393

@@ -154,6 +154,11 @@ Phaser.Physics.Arcade.Body = function (sprite) {
154154
*/
155155
this.maxVelocity = new Phaser.Point(10000, 10000);
156156

157+
/**
158+
* @property {Phaser.Point} friction - x
159+
*/
160+
this.friction = new Phaser.Point(1, 0);
161+
157162
/**
158163
* @property {number} angularVelocity - The angular velocity in pixels per second sq. of the Body.
159164
* @default

src/physics/arcade/World.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,23 @@ Phaser.Physics.Arcade.prototype = {
983983
{
984984
body1.x = body1.x - this._overlap;
985985
body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x;
986+
987+
// This is special case code that handles things like vertically moving platforms you can ride
988+
if (body2.moves)
989+
{
990+
body1.y += (body2.y - body2.prev.y) * body2.friction.y;
991+
}
986992
}
987993
else if (!body2.immovable)
988994
{
989995
body2.x += this._overlap;
990996
body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x;
997+
998+
// This is special case code that handles things like vertically moving platforms you can ride
999+
if (body1.moves)
1000+
{
1001+
body2.y += (body1.y - body1.prev.y) * body1.friction.y;
1002+
}
9911003
}
9921004

9931005
return true;
@@ -1103,7 +1115,7 @@ Phaser.Physics.Arcade.prototype = {
11031115
// This is special case code that handles things like horizontal moving platforms you can ride
11041116
if (body2.moves)
11051117
{
1106-
body1.x += body2.x - body2.prev.x;
1118+
body1.x += (body2.x - body2.prev.x) * body2.friction.x;
11071119
}
11081120
}
11091121
else if (!body2.immovable)
@@ -1114,7 +1126,7 @@ Phaser.Physics.Arcade.prototype = {
11141126
// This is special case code that handles things like horizontal moving platforms you can ride
11151127
if (body1.moves)
11161128
{
1117-
body2.x += body1.x - body1.prev.x;
1129+
body2.x += (body1.x - body1.prev.x) * body1.friction.x;
11181130
}
11191131
}
11201132

0 commit comments

Comments
 (0)