Skip to content

Commit

Permalink
Added dynamic 'heuristics' and 'preferY' properties to the Facade.
Browse files Browse the repository at this point in the history
This makes it easier to toggle these features globally.
  • Loading branch information
hexus committed Apr 3, 2017
1 parent 62f2bff commit d530f30
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,9 @@
- Fixed a heuristics mistake that's been around since May 2016 (4ee0d23c)! There
are probably more...
- Fixed a wrapping issue with tilemap layer debug rendering.
- Added dynamic `heuristics` and `preferY` properties to the Facade, making it
simpler to toggle these features globally (`game.slopes.heuristics`,
`game.slopes.preferY`).

## v0.2.0-beta - 10th February 2017
- Supported tile collision flags when determining separation (#27, #28,
Expand Down
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -145,12 +145,24 @@ right situations.
player.body.slopes.preferY = true;

// Prefer the minimum Y offset globally
game.slopes.solvers.sat.options.preferY = true;
game.slopes.preferY = true;
```

If you're making a platformer, your player has drag on the X axis, and you don't
want it to slide down slopes, this should solve your problem.

#### Heuristics

The plugin uses heuristics to prevent physics bodies from catching on
undesirable tile edges; the faces of two tiles placed next to each other.

**This is enabled by default.** If you don't need this feature, you can disable
it.

```
game.slopes.heuristics = false;
```

#### Collision pulling

To attempt to keep objects on a surface, you can use collision pulling.
Expand Down
36 changes: 36 additions & 0 deletions src/ArcadeSlopes/Facade.js
Expand Up @@ -168,3 +168,39 @@ Phaser.Plugin.ArcadeSlopes.Facade.prototype.convertTilemapLayer = function (laye
Phaser.Plugin.ArcadeSlopes.Facade.prototype.collide = function (i, body, tile, tilemapLayer, overlapOnly) {
return this.solvers[this.defaultSolver].collide(i, body, tile, tilemapLayer, overlapOnly);
};

/**
* Whether to prefer Y axis separation in an attempt to prevent physics bodies
* from sliding down slopes when they are separated.
*
* Disabled by default. Only relevant in a game that uses gravity.
*
* @name Phaser.Plugin.ArcadeSlopes.Facade#preferY
* @property {boolean} preferY
*/
Object.defineProperty(Phaser.Plugin.ArcadeSlopes.Facade.prototype, 'preferY', {
get: function () {
return this.solvers.sat.options.preferY;
},
set: function (enabled) {
this.solvers.sat.options.preferY = !!enabled;
}
});

/**
* Whether to use heuristics to avoid collisions with the internal edges between
* connected tiles.
*
* Enabled by default. Relevant to platformers.
*
* @name Phaser.Plugin.ArcadeSlopes.Facade#heuristics
* @property {boolean} heuristics
*/
Object.defineProperty(Phaser.Plugin.ArcadeSlopes.Facade.prototype, 'heuristics', {
get: function () {
return this.solvers.sat.options.restrain;
},
set: function (enabled) {
this.solvers.sat.options.restrain = !!enabled;
}
});

0 comments on commit d530f30

Please sign in to comment.