Jump to content

Read Object Layer from Tiled


damiansito
 Share

Recommended Posts

I have been playing around with Phaser for a couple of days now, but I have been stuck for like the past 3 days on just trying to set up collision with an object layer I set up in Tiled. I am using Arcade Physics here in the main branch. I tried creating the object layer, like you would with any normal tile layer, but the id is always null and errors out. I then did some research and found out that Phaser doesn't support object layers like that. Some objects (treasure chests) I have created in the object layer show up, however. The problem I am having is making the polylines convert to rigid bodies in order to collide with the player.

Update: Right now I am using various hacks to simulate something similar, but the original problem still stands.

You can see my code here: https://github.com/damianlajara/interactive-portfolio

I also tried using P2 Physics in order to use the method `convertCollisionObjects` to convert the polylines into objects, but that did not work either. You can find the code for that in the P2 branch I have set up.

 

Any help would be greatly appreciated!

Edited by damiansito
Updated code
Link to comment
Share on other sites

Here is the code I am using in one of my projects :

// In my loading state (but it can be anywhere actually)
game.load.tilemap('bob', '../assets/maps/bob.json', null, Phaser.Tilemap.TILED_JSON);

// Then in the create function
map = game.add.tilemap('bob');

// I create a group to store all my enemies
enemies = game.add.group();

// Then I create all the enemies from my map 'bob', from the layer called "objects", and with the name set to "enemy1". I also store them in my group enemies, and I tell to Phaser that they are corresponding to my custom object Enemy (which is a custom sprite class)
map.createFromObjects('objects', 'enemy', 'enemy1', 0, true, false, enemies, Enemy);

// Last thing to do, set up collision with the player in the update method
game.physics.arcade.collide(player, enemies);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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