Jump to content

Sprite doesn't collide using map.putTile


nicoloko02
 Share

Recommended Posts

Greetings!!!

It's my first time here.

So, my problem is, when I use map.putTile, I set the collidable tiles using map.setCollisionByExclusion([6]), but it's not working.

Let me show a piece of code here:

            game.physics.startSystem(Phaser.Physics.ARCADE);                         mapa = MapGen.gerarMapa([0, 50, 50, 45, 5, 0, 5]);            game.stage.backgroundColor = '#2d2d2d';            map = game.add.tilemap();            map.addTilesetImage('dungeon');            layer = map.create('mapa', 50, 50, 32, 32);            for (var x = mapa.length; x-- {                for (var y = mapa[x].length; y-- {                    if (mapa[x][y] == '.') {                        map.putTile(6, x, y, layer);                    }                    else {                        map.putTile(14, x, y, layer);                    }                }            }            layer.resizeWorld();            map.setCollisionByExclusion([6]);            personagem = game.add.sprite(100, 82, 'personagem');            game.physics.enable(personagem);            personagem.body.setSize(50, 41, 25, 20);            personagem.body.collideWorldBounds = true;

This code is in my create function, so, basically, I generate my map using "MapGen.gerarMapa([0, 50, 50, 45, 5, 0, 5]);" and I'm using "map.putTile(6, x, y, layer);" to put the floor, and "map.putTile(14, x, y, layer);" to put the wall, then I say that the just the tile 6 won't collide using "map.setCollisionByExclusion([6]);".

That's it, if anyone can help me solve this problem I would be very grateful.

Link to comment
Share on other sites

  • 1 month later...

If someone is having troubles to test the collision like I was doing, I found a solution for my problem.

For this, I separated the walls and floor in diferent layers, then started to use "this.physics.arcade.collide(person, wallLayer);" in the update function, that way worked very well. =-)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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