Jump to content

Generating tilemaps in 2.0.1


Recommended Posts

I've been staring at this problem for way too long, time to ask your help.

I'm trying to make a roguelike which uses dynamically generated tilemaps. This was kind of a hassle in 1.1.6, where you would still need a json file generated by Tiled to get started. Now in 2.0 we have :


I have seen the example http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=blank+tilemap.js&t=blank%20tilemap and of course that works fine. But when I try to implement it, I run into all kinds of trouble.

First off, I'm using Typescript, and clark has been doing a fine job updating the definitions (though some tilemap stuff still needs updating).

Second, since I'm using typescript my project is built modularly, so the setup is somewhat different than the example.

My project can be found here: https://github.com/cheshirepuss42/WordMine .This is still 1.1.6, as I havent been able to get it working in 2.0.1

What i run into is that when i just copy the code from the example into the create function of the level-state (https://github.com/cheshirepuss42/WordMine/blob/master/Wordmine/WordMine/States/Level.ts), I get:

ReferenceError: layer is not definedif (this.getLayerIndex(layer) !== null)

which happens in Phaser.Tilemap.CreateBlankLayer (which is called by tilemap.create). This is weird, as when i debug the example to check what the content of layer is, it is also undefined (but not giving the error above).

I'm sorry if this is all somewhat vague, but it's a weird problem.

Just to be complete here is the code in the create method where this happens (it's just a copy of the code from the example)

create() {            //  Creates a blank tilemap            this.Map = this.game.add.tilemap();            //  Creates a layer and sets-up the map dimensions.            //  In this case the map is 30x30 tiles in size and the tiles are 32x32 pixels in size.            var layer = this.Map.create('level1', 30, 30, 32, 32);            //  Add a Tileset image to the map            this.Map.addTilesetImage('tiles');}
Link to comment
Share on other sites

Hey mate :D

Is there any chance you could try the latest dev version of 2?

I went through the js a few nights ago and made sure all the legacy stuff is gone and any missing stuff added.  

I am currently messing around with tiles for my first time ever so on that side I am too much of a novice to help.


Link to comment
Share on other sites

It seems that the problem is that no variable layer was found, which is solved by replacing:

if (this.getLayerIndex(layer) !== null) 


if (this.getLayerIndex(this.layer) !== null)

The example runs well with that fix. I'm new to JavaScript and Phaser, so I dont know if it's the correct solution, could someone please verify it?

Link to comment
Share on other sites

Thanks so far, the latest updates the last few days have helped me along, but there is still one issue:

When i generate the tilemap I go over every tile in every layer to see what should be shown (based on a seperate grid which 'contains' the game).

To do this i call Tilemap.putTile(index,x,y,layer)

In 1.1.6 I could pass null as index, meaning there is no tile there (like where there is no wall in the wall-layer).

But in 2.0.1 this gives me the following error:

TypeError: this.map.tiles[tile.index] is undefinedset = this.map.tilesets[this.map.tiles[tile.index][2]];

which happens in TilemapLayer.render.

What do I pass in the index parameter to make it null like in 1.1.6?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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