I can’t add a tilemap no matter what I do. I used tiled and the phaser webpack template.
Here is the code:
import Phaser from 'phaser';
import tilemap from './assets/tilemap.png';
import untitled from './assets/untitled2.json';
var config = {
type: Phaser.WEBGL,
width: 800,
height: 600,
backgroundColor: '#2d2d2d',
parent: 'phaser-example',
pixelArt: true,
scene: {
preload: preload,
create: create,
update: update
}
};
var game = new Phaser.Game(config);
var controls;
function preload ()
{
this.load.image('tiles', tilemap);
this.load.tilemapTiledJSON('map', untitled);
}
function create ()
{
var map = this.make.tilemap({ key: 'map' });
// The first parameter is the name of the tileset in Tiled and the second parameter is the key
// of the tileset image used when loading the file in preload.
var tiles = map.addTilesetImage('cybernoid', 'tiles');
// You can load a layer from the map using the layer name from Tiled, or by using the layer
// index (0 in this case).
var layer = map.createLayer(0, tiles, 0, 0);
this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
var cursors = this.input.keyboard.createCursorKeys();
var controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
speed: 0.5
};
controls = new Phaser.Cameras.Controls.FixedKeyControl(controlConfig);
var help = this.add.text(16, 16, 'Arrow keys to scroll', {
fontSize: '18px',
padding: { x: 10, y: 5 },
backgroundColor: '#000000',
fill: '#ffffff'
});
help.setScrollFactor(0);
}
function update (time, delta)
{
controls.update(delta);
}
The untitled2.json is:
{ "compressionlevel":-1,
"height":6,
"infinite":true,
"layers":[
{
"data":[5, 3, 4, 3, 4, 6,
3, 4, 3, 4, 3, 4,
4, 3, 4, 3, 4, 3,
3, 4, 3, 4, 3, 4,
4, 3, 4, 3, 4, 3,
3, 4, 3, 4, 3, 4],
"height":6,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":6,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.9.2",
"tileheight":47,
"tilesets":[
{
"columns":8,
"firstgid":1,
"image":"tilemap.jpg",
"imageheight":48,
"imagewidth":384,
"margin":1,
"name":"tilemap",
"spacing":1,
"tilecount":8,
"tileheight":47,
"tilewidth":47
}],
"tilewidth":47,
"type":"map",
"version":"1.9",
"width":6
}
And the error is
Uncaught TypeError: curl.chunks is undefined
I don’t understand what is wrong. I followed the tutorial and all. Please help. Thank you.