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

Full-block tile in arcadeslopes not registering for collision #49

Closed therladbsgh closed 6 years ago

therladbsgh commented 6 years ago

I'm currently using the Arcade Slopes tileset (32px) provided in this repository. However, the tileset is showing some bizarre behavior; in particular, the first tile (full-block) is inconsistent in being collide-able.

Below is an example in Tiled of using the tileset in a map:

img1

However, when seen in the actual game, the selection of full-blocks on the top-right is not registered for collisions at all. Also, while the half-blocks are registered for collision when used in the house, it does not register for collision when placed next to a full-block (as seen in the stack of logs next to the house.)

img2

However, the tiles on the stack of logs WILL register for collision if there are other tiles directly adjacent to it. Below is an example in Tiled where I place more vertical half-blocks near the logs:

img3

In this case, when seen in the game, the collisions work as intended (although the tiles in the top-right are still not registered):

img4

I'm not sure if this is a bug, or if there is a specific criteria that needs to be required for full-blocks (and other blocks) to be registered for collision. Below is the relevant code for your reference. Here's the actual link to the repository if more information is needed. I'm also using Phaser CE (v2.8.4).

Game State:

preload() {
    this.game.load.image('sprite', 'assets/sprites/sprite.png');
    this.game.load.spritesheet('arcade-slopes-32', 'assets/map/arcade-slopes-32.png', 32, 32);
    this.game.load.tilemap('map', 'assets/map/example_map.json', null, Phaser.Tilemap.TILED_JSON);
    this.game.load.spritesheet('tileset', 'assets/map/tilesheet.png', 32, 32);
}

create() {
    ...
    const map = this.game.add.tilemap('map');
    map.addTilesetImage('tilesheet', 'tileset');
    map.addTilesetImage('collisions', 'arcade-slopes-32');
    for (let i = 0; i < map.layers.length; i++) {
      if (map.layers[i].name !== 'collisions') {
        map.createLayer(i);
      }
    }
    this.collisionLayer = map.createLayer('collisions');
    map.setCollisionBetween(0, 34, true, this.collisionsLayer);
    this.game.slopes.convertTilemapLayer(this.collisionLayer, 'arcadeslopes');
    this.collisionLayer.debug = true;
}

update() {
    ...
    if (player && player.sprite) {
      this.game.physics.arcade.collide(player.sprite, this.collisionLayer, () => {
        console.log("Hey");
      });
    }
  }
}
hexus commented 6 years ago

Hey there, thanks for taking the time to make such a clear example of this issue. I'll hopefully have some time to take a look soon and find out what's going on here.

hexus commented 6 years ago

Hey there!

After spending an hour or so trying to debug the plugin with your game running, I've realised it's not the plugin at fault.

Here's the error:

https://github.com/therladbsgh/rpg-web/blob/0dea01e/client/game/room/RoomClass.js#L73

this.collisionsLayer should be this.collisionLayer

As a result, setting the collision flags will then work correctly.

Cheers!

therladbsgh commented 6 years ago

Well, RIP... that was embarrassing. Thanks so much for taking the time.

hexus commented 6 years ago

No trouble, it gets the best of us. :)

I am looking to alleviate the need to call this manually at some point, in the future (#45).