Jump to content

Empty object array, although in the json file there are objects


galen
 Share

Recommended Posts

As the title says, I'm currently trying to get objects into my game, however this is not working. When I wrote console.log(map.objects);, I get this Object {ObjectLayer: Array[0]} but my objects array in the json file starts like this

 "draworder":"topdown",
         "height":30,
         "name":"ObjectLayer",
         "objects":[
                {
                 "height":40,
                 "id":2,
                 "name":"hej",

so there is obviously something there. Any ideas? And yes I am sure I'm using the same json file.

Link to comment
Share on other sites

What you've said is logged does not match up with the code snippet.

What do you actually want? The objects array in your code snippet?

Usually you'd just grab the json file, parse it, and (from the snippet) grab `draworder.objects`, but it sounds like maybe you are doing some other changes to the data first?

Seeing some actual code might help, it might be too long for a forum post but maybe whack parts of it into jsfiddle or something?

Link to comment
Share on other sites

Hi, thanks for the response. What I want are the objects in that array. I am able to use phaser tilemap to load my tilemap, but now I also want to have like start and ending points which will change tilemaps depending if the player has gotten to that point or not. However, for some reason map.objects does log the name of my objects layer in Tiled, but not the content of it. This snippet is what I use to load the map.

preload...
  game.load.tilemap('map', 'assets/map2.json', null, Phaser.Tilemap.TILED_JSON);

  game.load.image('tiles', 'assets/tile-32.png');

create...

  map = game.add.tilemap('map');
    
  console.log(map.objects);

It is obviously not complete, but that should be enough to see the objects, right?

Link to comment
Share on other sites

Ah, so tilemap does the conversion. Ok, I'm not familiar with either the Tiled format or how Phaser tilemap converts it.

What happens if you log just `map`? It should log out the map object, might help you poke through the data structure, of course, the conversion could be lossy (probably is) so not all the data may be in there, which would mean there is some issue with either the json format or the conversion.

I'm probably not the best person to help you, but, try logging that map object and poking through it, see if you can find the representation of your objects.

Link to comment
Share on other sites

Hi, I did some poking but to no avail. Instead I added a different of object in the Tiled Editor, a Tile Object. These objects do show up on the logging, which is something. My next step would then be to use the tilemap.createFromObjects function which there is a example of on this page, http://phaser.io/examples/v2/tilemaps/create-from-objects#gv. I'm also looking at the phaser documentation to see how to use it, unfortunately, it's also not working, but hopefully soon! I was able to create them! Yay!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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