mirvine

How do I load tile map with phaser 3

Recommended Posts

Hi,

I created a simple tilemap with tiled, and I'm trying to load it. The code and files can be seen here:

https://codesandbox.io/s/qqq47wqv3w

I'm not getting any errors in the console, but the canvas is just a black square. Any ideas what I am doing wrong?

      var game = new Phaser.Game(config);

      function preload() {
        this.load.image("tiles", "assets/tiles.png");
        this.load.tilemapTiledJSON("World", "assets/tilemap2.json");
      }
      function create() {
        this.map = this.add.tilemap("World");
        var tileset = this.map.addTilesetImage("tiles", "tiles");
        his.backgroundLayer = this.map.createStaticLayer("World", tileset);
      }

The timemap.json from Tiles is below:

{ "height":100,
 "infinite":false,
 "layers":[
        {
         "data":[3, 3, 3, 3, 3, 3, 3, 3, ...[data omitted]..., 3, 3],
         "height":100,
         "id":1,
         "name":"World",
         "opacity":1,
         "type":"tilelayer",
         "visible":true,
         "width":100,
         "x":0,
         "y":0
        }],
 "nextlayerid":2,
 "nextobjectid":1,
 "orientation":"orthogonal",
 "renderorder":"right-down",
 "tiledversion":"1.2.1",
 "tileheight":8,
 "tilesets":[
        {
         "columns":8,
         "firstgid":1,
         "image":"tiles.png",
         "imageheight":48,
         "imagewidth":64,
         "margin":0,
         "name":"tiles",
         "spacing":0,
         "tilecount":48,
         "tileheight":8,
         "tilewidth":8
        }],
 "tilewidth":8,
 "type":"map",
 "version":1.2,
 "width":100
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.