I am using phaser version 3.11.0.
When I am calling the line map.createStaticLayer('stone')
I am getting the following error.
However right before I am calling console.log(map)
the tileWidth
appears to be defined as 32. Without the createStaticLayer()
call the code runs with no errors and displays the background color defined in the config variable in index.html
. Also if I purposely misspell the word stone
I only get a warning that Cannot create tilemap layer, invalid layer ID given: stonze
.
I have been trying to figure out how to fix it but I’m really stuck on this issue.
scene-one.js
class SceneOne extends Phaser.Scene {
constructor () {
super('SceneOne');
}
init() {
}
preload() {
this.load.tilemapTiledJSON('map', 'assets/map/example_map.json');
this.load.image('tileset' , 'assets/map/tilesheet.png')
}
create(data) {
let map = this.add.tilemap('map');
map.addTilesetImage('tilesheet', 'tileset'); // tilesheet is the key of the tileset in map's JSON file
console.log("hi")
console.log(map)
map.createStaticLayer('stone')
console.log(map)
}
update(time, delta) {
}
}
var sceneOne = new SceneOne
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//cdn.jsdelivr.net/npm/phaser@3.11.0/dist/phaser.js"></script>
<script src="js/scene-one.js" type="text/javascript"></script>
<title>game</title>
</head>
<body>
<div id='game'></div>
<script>
const phaserConfig = {
type: Phaser.AUTO,
parent: "game",
width: 1280,
height: 720,
backgroundColor: "#5DACD8",
scene: [SceneOne]
};
const game = new Phaser.Game(phaserConfig);
</script>
</body>
</html>