Omar Nooristani
Omar Nooristani

Reputation: 71

Tilemap from Tiled not rendering in Phaser

I'm stuck in a rut with this game I'm trying to make. The tilemap I'm trying to use has an error stating as follows

Error 1: "Phaser.Tileset - image tile area is not an even multiple of tile size"
Error 2: "Uncaught TypeError: Cannot read property '2' of undefined"
Error 3: "Uncaught TypeError: Cannot read property 'type' of undefined"2

Here is a link to the code I'm using. http://pastebin.com/Dv00KGii

Upvotes: 6

Views: 5604

Answers (4)

Adam M.
Adam M.

Reputation: 1088

Inside the Tiled Map Editor, you need to assure that all the tileset images that you are using are embedded inside the tilemap .tmx project file. If any of the tileset images is included as an external .tsx, not embedded image then it will throw Uncaught TypeError: Cannot read property '2' of undefined" error when you will try to import inside the Phaser the exported JSON file from the Tiled Map Editor.

If you have forgotten to embed it at the beginning it is not a problem as you can always do it later. The editor has a useful icon to do it easily:

enter image description here

To see if you have any external tilesets that will produce this error, check if the exported tilemap JSON files contain any references to .tsx files.

Upvotes: 4

Glogo
Glogo

Reputation: 2884

Try embedding tileset in your tilemap. For me this fixed this eror: Uncaught TypeError: Cannot read property '2' of undefined"

Upvotes: 5

earlonrails
earlonrails

Reputation: 5182

This also happened to me. I found that my png image I was loading was 1280x720.

The example on Phaser website says to load the tilemap like this

map = game.add.tilemap('mario');

The documentation for the tilemap function is here. The function takes other parameters like the tile sizes. In my case the default 32x32 is invalid because 720/32 = 22.5. That number needs to be a round number. So I just cropped my image to 32*22 = 704. Then Phaser was able to load the png with the default tilemap settings. So then the default 32x32 will work otherwise you can change the height setting to 10 since 720 is divisible by 10. In that case Phaser should not throw an error. In my case I resized my image because the other tile images I was using were all 32x32 so it is easier to be consistent.

Also when creating the tilemap json it is best if the tileheight and tilewidth are multiples of your image and settings.

Upvotes: 0

Thorbjørn Lindeijer
Thorbjørn Lindeijer

Reputation: 2112

The error Phaser is reporting is the following:

"image tile area is not an even multiple of tile size"

So, apparently Phaser requires that the size of the tileset image is a multiple of your tile size. Tiled itself does not require this, but if you're using Phaser you should probably make sure there is no extra space in the tileset image.

Upvotes: 1

Related Questions