Ground collision with tilemap

Recommended Posts


I am trying to make a player to collide with the ground. But the ground has been imported from a tilemap using the tiled program. The collision is not working :(

This is the important part of my code:

collisionLayer = map.createStaticLayer('collisionLayer', tileset);

var players = findObjectsByType('player', map, 'objectsLayer');
player = this.physics.add.sprite(players[0].x, players[0].y, 'dude');
this.physics.add.collider(player, collisionLayer);

findObjectsByType is not a phaser native method, but it is working.

The code runs without errors, but the collision is not working.

I have attached the code.


Share this post

Link to post
Share on other sites

How did you determine that his collision tile id is 3? I'm having a similar problem - no matter what I've tried I can't get my player to collide with the layer:

var map = this.make.tilemap({
    key: 'map'

var collisionTiles = map.addTilesetImage("collisions");
var groundTiles = map.addTilesetImage("tileset");

var collisionLayer = map.createStaticLayer('Collisions Layer', collisionTiles);  
var layer = map.createStaticLayer('Tile Layer', groundTiles);
var layer2 = map.createStaticLayer('Tile Layer 2', groundTiles);
collisionLayer.setCollisionBetween(1, 1);

player = this.physics.add.sprite(460, 380, 'hero');

this.physics.add.collider(player, collisionLayer);

My map file is here:

Share this post

Link to post
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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.