Jump to content

Can't make sprite collide with tilemap made with Tiled


godlike0108
 Share

Recommended Posts

Hi all, I'm a newbie who just started learning phaser.

I have created a tile map with Tiled.

It is composed of two tiled layer: background & collision.

In collision layer I put some walls.

And in the game code,

I have loaded tilemaps, create them, and they shows perfectly.

Then I set the collision, and sense the collision in update();

I think it should make the sprite collide with wall, but it didn't.. 

I tried adding "collison" properties in Tiled as I found from some tutorials, but it didn't work either..

Can someone help me? 

 

I have my all code & img & json packed here... Thanks~

https://db.tt/AAdpu3zd


//load tilemaps in preload.
this.load.tilemap('zombieset', 'assets/tilemaps.json', null, Phaser.Tilemap.TILED_JSON);
this.load.image('tiles', 'assets/tileset.png');

//start physic systems
this.physics.startSystem(Phaser.Physics.ARCADE);


//create tiles, and it shows perfectly.
this.map = this.add.tilemap('zombieset');
this.map.addTilesetImage('tileset1', 'tiles');

//set collision.
this.map.setCollision(1);
this.layer = this.map.createLayer('background');
this.layer = this.map.createLayer('collision');
this.layer.resizeWorld();



//sensor collison in update()
this.physics.arcade.collide(this.asuna, this.layer);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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