Jump to content

how to collide sprite with layers?


Recommended Posts

hi guys

today i made simple tile map with tow layer, first layer is background, second layer is the road, i want my sprite can walk on the road and collide with background

when i make my sprite collide with the road layer my code is work, but when i make sprite collide with background it doesn't collide

this i smy code

create: function () { game.physics.startSystem(Phaser.Physics.ARCADE);map = game.add.tilemap('tilemap_lev1'); map.addTilesetImage('Shaw-Floors-Piazza-13-x-13-Mosaic-Tile-Accent-in-Multi-color');  layer1 = map.createLayer('bg_layer'); // i want it to collide  layer1.resizeWorld();layer2 = map.createLayer('road_layer');layer2.resizeWorld();  map.setCollisionByExclusion([], true, 'bg_layer');

and in update functin i use this

game.physics.arcade.collide(greens, layer1);

thanks in advance

Link to comment
Share on other sites

ok no answers, so i answer my self, i found where is my proplem now

the code is correct 100% but when create tile map by (tile) software

i filled all the map by first tile set then i added new layer, then i put the road overwrite the background, this is the problem

when create the road layer you should to erase the background tiles where you want to put your road, and dont put one tile over one

i hope i explain well my english so bad

here is the steps again

in tile software

new map

add your tile set

ok now we want to create the background layer, and fill all the map with background tiles

now we want to make small road on the map so

erase any background tile you want to put the road on,

click add new layer

ok now put your road, but remember dont put any road tile on any background tile, you should to erase background then put the road

now every thing work

Link to comment
Share on other sites


  • Recently Browsing   0 members

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