Jump to content

Colliding with newly loaded tilemap [1.1.5]


Heppell08
 Share

Recommended Posts

So after some serious trial and error i evetually got tilemaps unloading and loading on demand with a few tile functions. It's all clever stuff and working brilliantly!

My new issue and for some reason a very trivial issue at that!

Anytime i load the new tilemap after destroying the old tilemap i cant collide my player with it.

It sort of hangs a bit then drops through. At first i tried bringToTop(); then i tried killing and reloading the player at the new X/Y co-ords but still not able to collide. I then decided on a new var for a layer and called it layer2, set the physics for colliding with layer2 on a newly loaded tilemap and still i fall through the world.

I've no idea what i'm doing wrong and the only next best idea i have is reloading the whole state but that seems very wasteful and i know theres a simpler way. Heres some of the code im usng to achieve what i need based on map switching and recreating.

 

code:

var tileFunc1 = {    mapSwitch: function()    {        layer.destroy();        deathText.destroy();        map = this.add.tilemap('level02');        map.addTilesetImage('Space02', 'tiles');        layer2 = map.createLayer('Space02');        layer2.resizeWorld();        map.setCollision(211); // Main Floor        deathText = this.add.text(10,10,'Deaths: 0',{        font: "28px Arial",        fill: "#ff0044"        });        deathText.fixedToCamera = true;        deathText.color = 0xff0091;        jButton.bringToTop();        player.x = playerX;        player.y = playerY - 120;        this.physics.collide(player, layer2);    },

Thats the basics of this function im trying to use, any help appreciated on this collision stuff.

thanks :)

Link to comment
Share on other sites

yeah i declared layer2 var in update instead of in the tilefunction, works fine now.

update: function()     {        this.physics.collide(player, layer);        this.physics.collide(player, layer2);    )

Just needed to declare the unloaded layers in the update for when they need used. Didnt think i needed them loaded in instantly but you do haha :D

Thanks :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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