hexus / phaser-arcade-slopes

:triangular_ruler: A Phaser CE plugin that brings sloped tile collision handling to the Arcade Physics engine
MIT License
126 stars 16 forks source link

Offset tilemap layer support #26

Closed hexus closed 7 years ago

hexus commented 7 years ago

When a tilemap layer's fixedToCamera property is false, Arcade Physics works with offset tile maps, and everything looks okay as long as the camera isn't moved.

Support this in Arcade Slopes by passing through the tilemap layer to collision solvers.


A note on Phaser's tilemap layers:

Phaser's TilemapLayer implementation does thoroughly contradicts the fixedToCamera property with lines like these in its postUpdate() and _render* methods:

if (this.fixedToCamera)
{
    this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
    this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
}

this._scrollX = this.game.camera.view.x * this.scrollFactorX / this.scale.x;
this._scrollY = this.game.camera.view.y * this.scrollFactorY / this.scale.y;

So no matter where the TilemapLayer sprite is positioned, it will always scroll tiles with the camera. There is no way to override this without changing these methods.

This can be fixed by introducing a separation between the TilemapLayer's sprite position and its scrolling position, which will also help to fix mismatched collision as soon as the camera moves.

hexus commented 7 years ago

Sick. :ok_hand: