Hi,
Like I said, it’s my teacher’s code and it works for three layers even if I don’t verify the existence of layers. But you’re right it’s not complete :).
Here my JSON file :
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"format":"json",
"target":"sans_titre6.json"
}
},
"height":5,
"infinite":false,
"layers":[
{
"data":[1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1],
"height":5,
"id":1,
"name":"orange",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":5,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 49, 49, 49, 0, 0, 49, 0, 49, 0, 0, 49, 49, 49, 0, 0, 0, 0, 0, 0],
"height":5,
"id":2,
"name":"bleu",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":5,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":5,
"id":3,
"name":"violet",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":5,
"x":0,
"y":0
}],
"nextlayerid":4,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"left-up",
"tiledversion":"1.4.2",
"tileheight":16,
"tilesets":[
{
"columns":8,
"firstgid":1,
"image":"..\/tilesets\/4 BigSet.png",
"imageheight":432,
"imagewidth":128,
"margin":0,
"name":"4 BigSet",
"spacing":0,
"tilecount":216,
"tileheight":16,
"tilewidth":16
}],
"tilewidth":16,
"type":"map",
"version":1.4,
"width":5
}
The HTML code :
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="data:;base64,=">
<title>json tilemap</title>
<style>
body {margin: 0px; padding: 0px;}
canvas {border: 1px solid black;}
</style>
</head>
<body>
<canvas id="myCanvas" width="1280" height="1280"></canvas>
<script type="module" src="./js/prg.js"></script>
</body>
</html>
And the tileset I use :
I have three directories : js (js code), tilesets (tileset image png) and tilemap (json file). The HTML code is outside directories.
Thank you,