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

Collision between my Tileset and the Player


polansk1
 Share

Recommended Posts

Hi! i need help!

I have a tileset like a labyrinth and i will know how to set collisions between my Players and the walls of labyrinth(tileset). That's my actual code. All is working except that line: >>this.physics.world.collide( player, tileset ,null, this);<< 

What im doing wrong? 

function preload () {
  this.load.image('gameTiles', 'img/tileset_sprite.png');
  this.load.tilemapTiledJSON('level1', 'maps/tileset_walls.json');
  this.load.image('dude', 'img/dude.png');
}

function create () {
  // platform.............

  this.map = this.add.tilemap('level1');
  var tileset = this.map.addTilesetImage('tileset_sprite', 'gameTiles');
  this.walls = this.map.createStaticLayer('walls', tileset);

  // player..............

  player = this.physics.add.sprite(40, 40, 'dude');

  // collisions...........

  this.physics.world.collide(player, tileset, null, this);

  player.setCollideWorldBounds(true);
}

 

Link to comment
Share on other sites

ty man!! i got it! 

 

function create(){

    //platform

    this.map = this.add.tilemap('level1');    
    var tileset = this.map.addTilesetImage('tileset_sprite','gameTiles');
    walls = this.map.createStaticLayer('walls', tileset,0,0);
    


    //player
    
    player = this.physics.add.sprite(40, 40,'dude');
    

    walls.setCollisionBetween(1, 50);
    
    this.physics.add.collider(player, walls);
    

    //movimiento

    cursors = this.input.keyboard.createCursorKeys();

}

 

working :D

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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