Jump to content

recalculate collision with tilemap using p2


SimonLdj
 Share

Recommended Posts

Hi,

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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