arhedg
August 23, 2020, 7:09pm
1
In trying to import my map from Tiled, I am getting the following error:
Any suggestions? I included the bits of code I thought were relevant here (omitted spritesheets, etc)
Preload()
this.load.image("floortileset", 'floortileset.png');
var json = require('./map.json');
this.load.tilemapTiledJSON(this.MK, json);
Create()
this.Map = this.make.tilemap({key: this.MK});
const tileset = this.Map.addTilesetImage("..\/agora\/front\/src\/Phaser\/Game\/floortileset.png", "floortileset");
const starter = this.Map.createStaticLayer("start", tileset);
const worldLayer = this.Map.createStaticLayer("Tile Layer 1", tileset);
Can also include the json file if it would be helpful! Would really appreciate any help I have spent days on this already.
Milton
August 23, 2020, 7:34pm
2
Are you sure the path to the png is correct? Check the Network tab in Dev Tools.
And your key is strange, I canāt tell what āthis.MKā is. Something like {key: āmapā} is more obvious.
1 Like
arhedg
August 23, 2020, 7:47pm
3
I got the path to the png based on the JSON file provided to me by Tiled. It is in the same folder as this file, and substituting in ā./floortileset.pngā unfortunately doesnāt solve it either.
this.MK is the map key (āMKā) I store within the class that this exists within. I tried substituting just āmapā into both āthis.MKā and no success here either
Milton
August 23, 2020, 8:03pm
4
But did you check the Network tab? If it gives a 404, itāll tell you what path it expects.
1 Like
arhedg
August 23, 2020, 8:13pm
5
Am not seeing anything under the network tab, or any 404 error in console logs.
Hi,
Try this:
arhedg:
this.load.image("floortileset", '/your_folder_assets/floortileset.png'); // check in dev tools, network tab if the path is good, like Milton said
var json = require('./map.json');
this.load.tilemapTiledJSON('map1', json); // 'map1' but can be anything
Create()
this.Map = this.make.tilemap({key: 'map1', tileWidth: 16, tileHeight: 16});
const tileset = this.Map.addTilesetImage('Tile Layer 1', 'floortileset', 16, 16); // 16 are tiles sizes, i use them but perhaps it's not needed
const starter = this.Map.createStaticLayer("start", tileset); // start must correspond to a tiled layer
const worldLayer = this.Map.createStaticLayer("Tile Layer 1", tileset); Tile Layer 1 must correspond to a tiled layer
And in Tiled, when you create a map, you must choose embedded tileset (or something like this, i donāt remember the exact term
1 Like
Milton
August 23, 2020, 8:24pm
7
Press CTRL-F5 or CTRL-r when in the Network Tab. Does it say 200 or 404?
It canāt say nothing.
arhedg
August 23, 2020, 8:25pm
8
Still seems to be an error @BlunT76 , thank you though.
start and Tile Layer 1 are both tiled layers: "type":"tilelayer",
Perhaps my path in the JSON is wrong? I currently have
"tilesets":[
{
"columns":8,
"firstgid":1,
"image":"..\/agora\/front\/src\/Phaser\/Game\/floortileset.png",
"imageheight":272,
"imagewidth":272,
"margin":1,
"name":"floortileset",
"spacing":2,
"tilecount":64,
"tileheight":32,
"tilewidth":32
}],
Edit: And I did do the embedded tilesheet option
arhedg
August 23, 2020, 8:26pm
9
Ah, thanks, I am seeing 304 for most things.
arhedg
August 23, 2020, 9:03pm
10
If it helps, here is a screenshot of my GameScene object
Do you have your project on github or somewhere else to test it?
arhedg
August 23, 2020, 9:23pm
12
Iāll put it up in a sec ā I am just playing around with another repository and trying to get it to run on my localhost for my own education.
That said, I might have gotten closer to figuring it out. I am seeing that āconst tilesetā is null after adding the tileset image, which makes me think itās not being loaded properly.
Milton
August 23, 2020, 9:26pm
13
Iām still not convinced
Could you check disable cache (in the Network tab header) , and post the result of you hovering over āfloortileset.pngā?
Like this:
1 Like
arhedg
August 23, 2020, 9:53pm
14
@Milton lol, well you were right I was looking at the wrong thing but looks like it is 200.
Milton
August 23, 2020, 10:17pm
15
Another thing I noticed:
tilesetName - The name of the tileset as specified in the map data
Shouldnāt be the problem, but change it to addTileSetImage(āfloortilesetā); // or whatever you called it in Tiled.
Maybe look at this tutorial.