Jump to content

Invalid layer ID given: null when creating a layer


Rchristiani
 Share

Recommended Posts

I have searched a few times on this forum for this issue, but I can't seem to fix it based on the results.

 

I want to set up collision based on a polyline, so I add the info

GW.game.load.tilemap('collision', 'assets/ghost-wizard.json', null, Phaser.Tilemap.TILED_JSON);

And then:

GW.map = GW.game.add.tilemap('collision');GW.layer = GW.map.createLayer('collision');

On the createLayer line it is throwing the error, 'collision' is the name of the layer as well as the tilemap. When I inspect the element sent to the createLayer method I notice that the layer property is a completely emptya array. I have not altered the tilted JSON info at all. 

 

I am using Phaser version 2.0.5 dev branch. Any tips to help figure this one out.  Or let me know if you have if any other info is needed. 

 

Thanks

Link to comment
Share on other sites

  • 1 year later...

nope, you can't use createLayer on an Object layer, it's only for Tile layers

 

if you're using p2 you can use convertCollisionObjects
https://www.mvcodeclub.com/lessons/creating-enemies-and-collisions-in-phaser-and-tiled

var walls = game.physics.p2.convertCollisionObjects(map, "Collisions", true); for(var wall in walls) {     walls[wall].setCollisionGroup(wallsCG);     walls[wall].collides(playerCG); }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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