Jump to content

[Phaser 2.9.3] Problem with TileMap?


ZRT
 Share

Recommended Posts

Hey guys. I've been trying to get Phaser 2.9.3 with the latest TileMap (v1.1.1). It fails on a simple tileset preload. I haven't touched Phaser since early version, not sure if what I do here is right anyway. I looked around the forum for similar problems, but nothing solved it so far.

Any help is appreciated. Thanks in advance.

So, the error first:

Quote

phaser.min.js:3 Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas

And here's the very simple code:

var game = new Phaser.Game(1600, 800, Phaser.AUTO, 'phaser', { preload: preload, create: create, update: update, render: render });

function preload() {
    this.game.load.tilemap('tilemap', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON);
    this.game.load.image('tiles', 'assets/space.png');
    console.log('preloads');
}

function create() {
  game.stage.backgroundColor = '#666';
    map = game.add.tilemap('tilemap');
    map.addTilesetImage('tile', 'tiles');
    layer = map.createLayer('layer');
    layer.resizeWorld();
}

function update() {

}

function render() {

}

And the .json file I think it's the culprit.

{ "height":20,
 "infinite":false,
 "layers":[
        {
         "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19],
         "height":48,
         "name":"layer",
         "opacity":1,
         "type":"tilelayer",
         "visible":true,
         "width":48,
         "x":0,
         "y":0
        }],
 "nextobjectid":1,
 "orientation":"orthogonal",
 "renderorder":"right-down",
 "tiledversion":"1.1.1",
 "tileheight":48,
 "tilesets":[
        {
         "columns":8,
         "firstgid":1,
         "image":"space.png",
         "imageheight":1530,
         "imagewidth":384,
         "margin":0,
         "name":"tile",
         "spacing":0,
         "tilecount":248,
         "tileheight":48,
         "tilewidth":48,
         "source:": "space.png"
        }],
 "tilewidth":48,
 "type":"map",
 "version":1,
 "width":30
}

 

Link to comment
Share on other sites

I got this working with an older version of Tiled (0.14.2) on Linux. 

Here's the working code.

var game = new Phaser.Game(800, 640, Phaser.AUTO, 'phaser', { preload: preload, create: create, update: update, render: render });

function preload() {
  game.load.tilemap('tilemap', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON);
  game.load.image('tiles', 'assets/atlas.png');
}

function create() {
  game.stage.backgroundColor = '#666';
  map = game.add.tilemap('tilemap');
  map.addTilesetImage('atlas', 'tiles');
  layer = map.createLayer('layer');
  layer.resizeWorld();
}

function update() {

}

function render() {

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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