Skip to content

Commit

Permalink
Arcade.Body.friction allows you to have more fine-grained control o…
Browse files Browse the repository at this point in the history
…ver the amount of velocity passed between bodies on collision.
  • Loading branch information
photonstorm committed Jan 18, 2015
1 parent 6fb816a commit 587c3e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -63,10 +63,11 @@ Version 2.3.0 - "Tarabon" - in dev
### New Features

* `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.
* `Arcade.Body.friction` allows you to have more fine-grained control over the amount of velocity passed between bodies on collision.

### Updates

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

### Bug Fixes

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

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

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.
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.

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)

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.
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.

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*.
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*.

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.

Expand Down
7 changes: 6 additions & 1 deletion src/physics/arcade/Body.js
Expand Up @@ -87,7 +87,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
this.width = sprite.width;

/**
* @property .numInternal ID cache
* @property {number} height - The calculated height of the physics body.
*/
this.height = sprite.height;

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

/**
* @property {Phaser.Point} friction - x
*/
this.friction = new Phaser.Point(1, 0);

/**
* @property {number} angularVelocity - The angular velocity in pixels per second sq. of the Body.
* @default
Expand Down
16 changes: 14 additions & 2 deletions src/physics/arcade/World.js
Expand Up @@ -983,11 +983,23 @@ Phaser.Physics.Arcade.prototype = {
{
body1.x = body1.x - this._overlap;
body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x;

// This is special case code that handles things like vertically moving platforms you can ride
if (body2.moves)
{
body1.y += (body2.y - body2.prev.y) * body2.friction.y;
}
}
else if (!body2.immovable)
{
body2.x += this._overlap;
body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x;

// This is special case code that handles things like vertically moving platforms you can ride
if (body1.moves)
{
body2.y += (body1.y - body1.prev.y) * body1.friction.y;
}
}

return true;
Expand Down Expand Up @@ -1103,7 +1115,7 @@ Phaser.Physics.Arcade.prototype = {
// This is special case code that handles things like horizontal moving platforms you can ride
if (body2.moves)
{
body1.x += body2.x - body2.prev.x;
body1.x += (body2.x - body2.prev.x) * body2.friction.x;
}
}
else if (!body2.immovable)
Expand All @@ -1114,7 +1126,7 @@ Phaser.Physics.Arcade.prototype = {
// This is special case code that handles things like horizontal moving platforms you can ride
if (body1.moves)
{
body2.x += body1.x - body1.prev.x;
body2.x += (body1.x - body1.prev.x) * body1.friction.x;
}
}

Expand Down

0 comments on commit 587c3e5

Please sign in to comment.