Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Collision with newly created tiles


przemoo83
 Share

Recommended Posts

ah sorry, didn't read the question properly.

 

 

convertTilemap... Goes through all tiles in the given Tilemap and TilemapLayer and converts those set to collide into physics bodies. Only call this after you have specified all of the tiles you wish to collide with calls like Tilemap.setCollisionBetween, etc. Every time you call this method it will destroy any previously created bodies and remove them from the world. Therefore understand it's a very expensive operation and not to be done in a core game update loop.

 

 

it looks like you're going to have to manually add the body to the tile you created at runtime

 

look around line 1758

https://github.com/photonstorm/phaser/blob/858ad5161028d45d65679c88fc1e9a08ceed1f8f/src/physics/p2/World.js

 

I don't know if there's a function to do it ... 

Link to comment
Share on other sites

this is guesswork based on that code... it works but i don't know if i've added it to the right place in the end

 

    if(this.game.input.mousePointer.isDown)    {                    var tile = map.putTile(40, layer1.getTileX(marker.x), layer1.getTileY(marker.y), layer1);        // add the body        var body = game.physics.p2.createBody(marker.x, marker.y, 0, false);        body.addRectangle(tile.width, tile.height, tile.width / 2, tile.height / 2, 0);        game.physics.p2.addBody(body);        layer1.bodies.push(body);             }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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