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

Collision with Tile map


pdiddles03
 Share

Recommended Posts

I have a tilemap and i need to add collision with the map.  I've seen people use map.setCollision(40); or map.setCollisionBetween(40); but i don't think that is a legitimate way of setting collision in a map. I need to set the collision for the entire layer itself. How do i go about this given the following code:

function preload(){
      game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
      game.scale.pageAlignHorizontally = true;
      game.scale.pageAlignVertically = true;
      game.physics.startSystem(Phaser.Physics.ARCADE);

      game.load.spritesheet('sprites','images/images.png','images/images.json');
      game.load.spritesheet('player','images/player.png',16,16);
      game.load.tilemap('map','images/tilemap.json',null,Phaser.Tilemap.TILED_JSON);


    }
    function create(){
      map = game.add.tilemap('map');
      map.addTilesetImage('tileset', 'sprites');
      layer = map.createLayer('World 1');
      layer.resizeWorld();
      player = game.add.sprite(16,16,'player');
      game.physics.enable(player,Phaser.Physics.ARCADE);
      player.frame = 0;
      player.animations.add('walk', [0,1,2], 7, true)
      player.animations.play('walk');
      player.body.velocity.set(35,0);
      player.body.collideWorldBounds=true;
      player.body.bounce.set(1);
    }
    function update(){
      game.physics.arcade.collide(player, layer);
    }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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