Jump to content

P2 tilemap collision


Raikoh
 Share

Recommended Posts

Im using tilemap with P2 and it says to set the tiles that you want to collide with (map.setCollisionBetween()) but even without this line all my tiles collide. 

I tried to set the collides parameter to false and the tiles still collides. In the P2 physique example "tilemap gravity" if i delete the line map.setCollisionBetween(1, 12) it doesn't change anything. ConvertTilemap is supposed to work only on the tiles that we define with map.setCollision, but it uses all the tiles on the layer. Is it a bug, or i don't get it?

Link to comment
Share on other sites

I'm pretty sure this is a bug in the engine. In the source for p2.convertTilemap, a collision body is only *ignored* for a tile if the tile doesn't actually exist (aka the index is 0), regardless of if setCollisionBetween is set on it or not.

 

To fix, go to line 69015 of phaser.js; you should see

                if (tile)

change that to

                if (tile && tile.collides)
Link to comment
Share on other sites

I'm using a updated dev build (build with grunt) and my tilemap still disappears after the first p2 physics collision. I have a seperate collision mesh for the ground and the tilemap is just for visual represantation so i dont wont it to collide with anything and just stay in place. Doesnt work for me so far no matter what im trying.

Link to comment
Share on other sites

yes, the camera follow works, i tried disabling everything and moved the camera with the cursors like in this example, and the tilemap still disappears, when im not moving the camera everything is fine. http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=csv+map.js&t=csv%20map Im using a Tilemap JSON File generated by Tiled btw.

 

Simple code:

var map = this.game.add.tilemap('level1');map.addTilesetImage('Level_1', 'tiles');                var layer = map.createLayer('Layer1');layer.resizeWorld();
Link to comment
Share on other sites

I'm doing the exact same thing as you. Using Tiled and exporting to JSON. 

 

 

function preload() {    game.load.tilemap('map', 'content/maps/Test01.json', null, Phaser.Tilemap.TILED_JSON);    game.load.image('tileset1', 'content/images/tileset.png', 32, 32);    game.load.spritesheet('player', 'content/images/test.png', 24, 32, 12);}function create() {    game.physics.startSystem(Phaser.Physics.P2JS);    // create map    map = game.add.tilemap('map');    map.addTilesetImage('tileset1');    layer1 = map.createLayer('Ground');    layer1.resizeWorld();    layer2 = map.createLayer('Object');    layer2.resizeWorld();    layer3 = map.createLayer('Foreground');    layer3.resizeWorld();}
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...