loadMapFromCSV not working with tiled map editor



  • I am using the tiled map editor and then export to CSV. Blank tiles in that file are represented by -1 while other code use 0. How can I use tiled map editor with the following code?

    level.loadMapFromCSV(Assets.getText("assets/data/Map.csv"), "assets/images/tiles.png", 16, 16); add(level);



  • It should have an optional argument of starting index. Try changing it



  • @starry-abyss
    I have already tried that. Here is an example.
    level.loadMapFromCSV(Assets.getText("assets/data/Map.csv"), "assets/images/tiles.png", 16, 16,AUTO,0); add(level); var objectData:String = Assets.getText("assets/data/Map_Objects.csv");
    this map and the object map do not seem to work together.
    for (i in 0...objectsString.length) objects.push(Std.parseInt(objectsString[i])); for (x in 0...objects.length) { switch(objects[x]) { case 0: addPlayer(x, y);



  • I have a very strange error with the code. in the object csv file there is no 0, yet in the code above this message it goes to case 0 because for some reason the player is created. when i add a 0 to that file, two players are created yet one is seen falling. I can verify this by changing the code to case 0 addPlayer(16,16). when i run the code, two is seen, one that stays in position and the other player that falls with gravity.

    the first tile is blank for both tilemap images that were used to create the csv maps in tiled map editor.

    		level = new FlxTilemap();
    		level.loadMapFromCSV(Assets.getText("assets/data/Map_Level.csv"), "assets/images/tiles.png", 16, 16, 0, 0, 0);
    		add(level);
    
    		var objectData:String = Assets.getText("assets/data/Map_Objects.csv");
    		var rows:Array<String> = objectData.split("\n");
    		
    		for (y in 0...rows.length) {
    			var objectsString:Array<String> = rows[y].split(",");			
    			var objects:Array<Int> = new Array();
    
    			for (i in 0...objectsString.length) objects.push(Std.parseInt(objectsString[i]));
    			for (x in 0...objects.length) {
    
    				switch(objects[x]) {
    					case 0: addPlayer(x, y);
    				}
    			}
    		}
    




  • @galoyo
    you might have a blank line in the csv file that ends up being a 0. Try checking if (rows[y].length > 0) to skip blank lines.



  • @dean
    ty dean. gee, i only spent hours on this thing and i read about the blank line bug report to and completely forgot about that.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.