Jump to content

Phaser: Multiple TilemapLayer collision problem


Larzan
 Share

Recommended Posts

Hi,

i separated my collectables, tiles (scene, blocking movement) and eye candy into different TilemapLayers using the same tilemap (created with Tiled).

 

They display just fine, but the collision is only detected for the first tilemap in the tiled file!

If i switch the positions of the layers in the JSON file, it is the other way around, ONLY for the first layer of the JSON the collision will be detected correctly, the position in my source code does not matter, ONLY the position in the JSON file.

 

Did i miss something in the docs, do i have to activate collisions manually for all layers other than the first?

 

Here the relevant TypeScript code:

...    leveldata: {        playerblocks:       Phaser.Group // here we put the players turned to blocks        tilemap:            Phaser.Tilemap        layer_collectables: Phaser.TilemapLayer        layer_tilelayer:    Phaser.TilemapLayer       layer_eyecandy:      Phaser.TilemapLayer    };...createLevel() {    ....    this.leveldata.tilemap = this.add.tilemap('map'); // Preloaded tilemap    this.leveldata.tilemap.addTilesetImage('test-level2', 'test_tiles2'); // Preloaded tileset    // activate collision for blocks a till b    this.leveldata.tilemap.setCollisionBetween(80, 140);    // catch collect events for ...    this.leveldata.tilemap.setTileIndexCallback(        [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,80], this._collectIt, this);    // TILE LAYERS    this.leveldata.layer_tilelayer = this.leveldata.tilemap.createLayer('Tile Layer 1');     this.leveldata.layer_eyecandy = this.leveldata.tilemap.createLayer('Eye Candy');    this.leveldata.layer_collectables = this.leveldata.tilemap.createLayer('Collectables');    this.leveldata.layer_tilelayer.resizeWorld(); // Sets the world size to match the size of this layer.}....update() {    ....    var collidecollectables = this.game.physics.arcade.collide(this.player, this.leveldata.layer_collectables);    var collidetiles = this.game.physics.arcade.collide(this.player, this.leveldata.layer_tilelayer);    var collidebpblocks = this.game.physics.arcade.collide(this.player, this.leveldata.playerblocks)    var touching = (collidebpblocks || collidetiles);    ....}

p.s.: beside the collision detection the callback works neither but for the layer which comes first in the JSON file. All layers use the same tiles

Phaser version 2.0.7

Link to comment
Share on other sites

Yo!

Try to pass the layer name to 

setCollisionBetween(start, stop, collideslayerrecalculate)

 

My problem was solved by that way

var introMap = this.game.add.tilemap('map');introMap.addTilesetImage('tileset');this.introLayer = introMap.createLayer('menu');this.introLayer.resizeWorld();introMap.setCollision([1,3], true, 'menu');
Link to comment
Share on other sites

Perfekt, thanks :)

 

I was looking for the solution to this problem for a while, but somehow i didn't think to check if there were more than the parameters i was using.

 

Worked smoothly, i managed to use more than one tilemap as background and have one dedicated tilemap only for collectables (even though i could also use several ones there)

works like a charm :)

...// activate collision for blocks a till bthis.leveldata.tilemap.setCollisionBetween(80, 140, true, 'Tile Layer 1');// catch collect events for ...this.leveldata.tilemap.setTileIndexCallback(    [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,80], this._collectIt, this, 'Collectables');...

:)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...