Jump to content

Dynamic CSV Tilemap Single Row Issue - SOLVED


tinker
 Share

Recommended Posts

Hi everyone.

I am currently at the beginning phases of creating the portion of my code that will update/create my map from an algorithm I will create later. For now I am randomizing it. I am using the csv option of tilemap but running into a problem I can't figure out and I have read everything I can to no avail.

I have this in my preload():

game.load.image('worldMapTiles', '/public/assets/mapspritesheet.png');

function generateWorldTilemapCSV() {
           ** Random code here - save the space by leaving it out of post here is a copy and paste of its return from the console:
   "3,1,2,1,1,0,2,3,2,1,2,3,3,2,1\n2,2,1,3,0,2,3,1,0,1,3,2,3,1,2\n1,2,2,3,3,2,2,0,1,1,1,3,3,3,3\n1,1,2,2,1,0,2,2,3,1,3,2,2,2,3\n2,2,3,3,1,1,2,1,3,1,2,1,1,1,2\n1,2,3,1,2,3,1,2,1,2,2,2,1,3,3\n2,2,3,1,1,1,3,1,3,1,1,1,2,3,2\n1,1,1,3,1,3,3,2,1,3,1,2,2,1,3\n3,1,3,2,1,3,2,0,1,2,1,2,3,2,0\n3,2,2,1,1,3,2,3,2,1,2,1,1,1,2\n1,2,3,1,1,2,2,3,0,2,3,2,3,1,1\n3,3,3,1,2,2,1,3,1,2,1,2,2,2,3\n3,1,2,2,3,2,2,1,2,2,1,3,2,1,2\n1,3,1,3,3,1,1,1,1,1,3,2,1,2,1\n1,2,3,3,2,1,2,1,3,3,1,3,3,2,3\n"
**
            };

game.load.tilemap('worldMap', null, generateWorldTilemapCSV(), Phaser.Tilemap.CSV);

... and in my create()

map = game.add.tilemap('worldMap', 200, 200);
map.addTilesetImage('worldMapTiles');

However all this does for some reason is create one 200 pixel tall row that is very wide (essentially all the tiles horizontally) as if it is ignoring the '\n'.

 

 

'mapspritesheet.png' is a simple 400x400 image ([4] 200x200 squares). I have no errors in the console. I am new so I have a feeling I am missing something obvious but I promise I have spent hours on this already before asking. Thank you in advance for your help.

 

UPDATE: Well it is now been multiple days and this post still has not been approved - figured it out  - the string needs to have the new line double escape like this '1\\n' which means that in my random map generator I had to add  three slashes like so: '\\\n' when appending it.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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