Jump to content

Help loading tilemaps from CSV


Will
 Share

Recommended Posts

Hello there, I have been updating my game to the newest phaser (the game was tiny - just a prototype), and I get an error when I try to load a tilemap.

 

The error -

 

y2K5wb5.png

 

Here is my code:

State.Game.preload = function(){	game.load.tilemap('room', null, Gen.generateRoom(), Phaser.Tilemap.CSV);		game.load.image('tiles', 'assets/tileset.png');	game.load.image('player', 'assets/sprites/player.png');	//State.Game.cursors = game.input.keyboard.createCursorKeys();};State.Game.create = function(){			    State.Game.map = game.add.tilemap('room');    State.Game.map.addTilesetImage('tiles');      State.Game.layer = State.Game.map.createLayer('Game World', 800, 600);    State.Game.layer.resizeWorld();    //cursors = game.input.keyboard.createCursorKeys();    //Sprite.addPlayer();        	};

My generateRoom function returns strings that look like this -

"1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1"

Though I don't think it is that, as it worked fine before.

Link to comment
Share on other sites

It may be a phase bug cause you have:
 

/*** Creates a new Tilemap object.** @method Phaser.GameObjectFactory#tilemap* @param {string} key - Asset key for the JSON or CSV map data in the cache.* @param {object|string} tilesets - An object mapping Cache.tileset keys with the tileset names in the JSON file. If a string is provided that will be used.* @return {Phaser.Tilemap} The newly created tilemap object.*/tilemap: function (key, tilesets) {return new Phaser.Tilemap(this.game, key, tilesets);},

But the Tilemap class gets:

Phaser.Tilemap = function (game, key) {

I'm not a phaser user so I may be wrong xD

Link to comment
Share on other sites

 

It may be a phase bug cause you have:

 

/*** Creates a new Tilemap object.** @method Phaser.GameObjectFactory#tilemap* @param {string} key - Asset key for the JSON or CSV map data in the cache.* @param {object|string} tilesets - An object mapping Cache.tileset keys with the tileset names in the JSON file. If a string is provided that will be used.* @return {Phaser.Tilemap} The newly created tilemap object.*/tilemap: function (key, tilesets) {return new Phaser.Tilemap(this.game, key, tilesets);},

But the Tilemap class gets:

Phaser.Tilemap = function (game, key) {

I'm not a phaser user so I may be wrong xD

 

 

Thanks for that, hopefully it isn't a bug...

Link to comment
Share on other sites

I haven't used 1.1.4 yet, but from the examples it looks like this part maybe backwards. I could be wrong though.

 

Yours:

game.load.tilemap('room', null, Gen.generateRoom(), Phaser.Tilemap.CSV);

 example should be:

game.load.tilemap('room', Gen.generateRoom(), null,  Phaser.Tilemap.CSV);
Link to comment
Share on other sites

 

I haven't used 1.1.4 yet, but from the examples it looks like this part maybe backwards. I could be wrong though.

 

Yours:

game.load.tilemap('room', null, Gen.generateRoom(), Phaser.Tilemap.CSV);

 example should be:

game.load.tilemap('room', Gen.generateRoom(), null,  Phaser.Tilemap.CSV);

 

Thanks, but that doesn't seem to be the solution :|

 

That gives me this error - http://prntscr.com/2qmmk5

 

Which I believe is due to the fact that the second parameter is for the path to a tilemap JSON file :)

Link to comment
Share on other sites

I am not sure with CSV files, I use JSON and got it to work. One thing I see is that in my file the values are in an array and they are not in your generate function. Although I don't know if they are suppose to be in an array in  a CSV file. 

Here is my data 

[0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 1, 23, 9, 0, 1, 0, 0, 0, 0, 0, 5, 0, 13, 17, 5, 0, 0, 0, 0, 0, 0, 0, 1, 21, 9, 0, 0, 0, 0, 0, 0, 0, 5, 0, 13, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 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]
Link to comment
Share on other sites

I can't get CSV to work either, I get the same length error as Will. This is in 1.1.4.

The error occurs in: Phaser.Tileset#getIndex because the location array parameter is undefined.

So it most likely is a bug then. I reverted back to 1.1.3 for now. Hopefully Rich will see this...

Link to comment
Share on other sites

I am also getting this error when I attempt to load the tilemap from TILED_JSON

 

http://prntscr.com/2rvtha

 

However, I put a few console logs in the Phaser source, to see whether the layer and index properties within the function were set properly - the layer property was defined, however it seems that getIndex was not returning a proper index.

 

To be fair, I am not really sure what I am doing wrong, if anything. 

 

EDIT: I did try editing the function, so that the index was just set to 0. This seemed to work, though my tilemap was just white - maybe because I haven't really spent any time setting up the tileset stuff properly :P For now I will be sticking to 1.1.3, until the CSV stuff is sorted.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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