Jump to content

Loading Tiled map: layers and other properties not saving correctly


Rissk13
 Share

Recommended Posts

Hi there, new user to Phaser and Tiled so not sure if this is an issue with my code or a bug, but thought I'd try here first.

I'm trying to create a tilemap with an exported Tiled json map. I'm using Parcel so when I import via

import map001 from "assets/tilemaps/map001.json";

and console.log it out, everything looks right.

  1. {height: 64, infinite: false, layers: Array(7), nextobjectid: 28, orientation: "orthogonal", …}
    1. height:64
    2. infinite:false
    3. layers:(7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
    4. nextobjectid:28
    5. orientation:"orthogonal"
    6. renderorder:"right-down"
    7. tiledversion:"1.1.5"
    8. tileheight:32
    9. tilesets:(4) [{…}, {…}, {…}, {…}]
    10. tilewidth:32
    11. type:"map"
    12. version:1
    13. width:64

But then, when I create my tilemap

this.map = this.make.tilemap("map001");

It only saves some of the config:

  1. Tilemap
    1. currentLayerIndex:0
    2. format:null
    3. height:10
    4. heightInPixels:320
    5. imageCollections:[]
    6. images:[]
    7. layer:(...)
    8. layers:[]
    9. objects:{}
    10. orientation:"orthogonal"
    11. properties:{}
    12. scene:GameScene {sys: Systems, anims: AnimationManager, cache: CacheManager, plugins: PluginManager, registry: DataManager, …}
    13. tileHeight:32
    14. tileWidth:32
    15. tilesets:(4) [Tileset, Tileset, Tileset, Tileset]
    16. version:"1"
    17. width:10
    18. widthInPixels:320

As you can see, height and width are 10,layer and layers are empty (not sure the difference), and more. 

I'm using Phaser 3.10.1 and Tiled 1.1.5

Link to comment
Share on other sites

So I think I figured it out, if anybody else stumbles here for the same issues. I successfully created the tilemap, I had to change it to:

this.map = this.make.tilemap({ key: "map001" });

I also had to mess around with creating the layers and ended up with:

this.map.createStaticLayer("Ground", groundTileset);

"Ground" is the name of my layer from Tiled, groundTileset is from:

groundTileset = this.map.addTilesetImage("ground", "groundTiles")

I didn't think I'd need to specify the Tileset since I embedded them into the map. I thought that was required if you use multiple tilesets per layer in Tiled, so I'm not sure if there's a way to do that in Phaser. I tried passing the name of the embedded tileset instead but that didn't work. Will follow up here if I figure that out too.

Link to comment
Share on other sites

The parcel part was easy in comparison to learning Phaser 3/Tiled with no previous phaser/game dev experience :) Definitely thinking of posting a tutorial or at least my source code when it gets to a decent stage to share with others, I'll link it here when I do.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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