Jump to content

recalculate collision with tilemap using p2


Recommended Posts



I'm trying basically to combine those two examples

p2 tilemap: http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=tilemap.js&t=tilemap

and tilemaps paint tiles: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=paint+tiles.js&t=paint%20tiles


My problem is updating the collision for the new tiles.

I call game.physics.p2.convertTilemap(map, layer);

first time in create() and again in update() (only if user clicked the map)
once I call convertTilemap the second time I get this exception:
 Uncaught TypeError: Cannot set property 'body' of null Phaser.Physics.P2.Body.destroy                         Phaser.Physics.P2.clearTilemapLayerBodies              Phaser.Physics.P2.convertTilemap updateTilemap update Phaser.StateManager.update                             Phaser.Game.updateLogic                                Phaser.Game.update                                     Phaser.RequestAnimationFrame.updateRAF                 Phaser.RequestAnimationFrame.start._onLoop

As I understand the problem is my p2 body don't have a sprite (a p2.Body represent one of the tiles), than calling

        this.sprite.body = null;
throws the exception. 


Is any p2.Body should have a sprite? If yes, why my don't have one. if no, isn't that a bug?


Am I doing something wrong?


Thank you!

Link to comment
Share on other sites

I also noticed just calling clearTilemapLayerBodies right after convertTilemap like this

    game.physics.p2.convertTilemap(map, layer);    game.physics.p2.clearTilemapLayerBodies(map, layer);

throws same exception...


Any ideas anyone?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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