Tile 0 Next to Tile 32?



  • Is there a way to check to see if one tile is next to another? And if it is, change it to another tile?



  • I think a for loop could do the trick here.. something like

    for (j in 0...map.heightInTiles)		
    	for (i in 0...map.widthInTiles-1)		
    		if(map.getTile(i,j) == 0 && map.getTile(i+1,j) == 32)
    			map.setTile(i,j,newIndex,true);
    

    if you more complex checks you should probably check this tutorial.



  • Here's a snippet of how I do home-made auto-tiling using one source tilemap and several output ones (for top-down angled view):

    function isWall(x: Int, y: Int): Bool
    	{
    		if ((x < 0) || (y < 0) || (x >= map.widthInTiles) || (y >= map.heightInTiles))
    			return false;
    			
    		var tileID2 = map2.getTile(x, y);
    		if (tileID2 == 58)
    			return true;
    		
    		if ((tileID2 >= 87) && (tileID2 <= 90))
    			return false;
    		
    		var tileID = map.getTile(x, y);
    		if ((tileID == TILE_WALL) || (tileID == TILE_WALL_LEFT) || (tileID == TILE_WALL_RIGHT)
    			|| (tileID == TILE_WALL_TOP) || (tileID == TILE_WALL_BOTTOM))
    		{
    			return true;
    		}
    		
    		return false;
    	}
    	
    function isPit(x: Int, y: Int): Bool
    	{
    		if ((x < 0) || (y < 0) || (x >= map.widthInTiles) || (y >= map.heightInTiles))
    			return false;
    		
    		var tileID = map.getTile(x, y);
    		if (tileID == TILE_PIT)
    		{
    			return true;
    		}
    		
    		return false;
    	}
    
    function setDecorUp(x: Int, y: Int, tileID: Int)
    	{
    		map3.setTile(x, y - 1, tileID);
    	}
    	
    function setReal(x: Int, y: Int, tileID: Int)
    	{
    		map2.setTile(x, y, tileID);
    	}
    
    ......
    
    for (x in 0...map.widthInTiles)
    for (y in 0...map.heightInTiles)
    	{
    	var tileID: Int = map.getTile(x, y);
    
          ......
    
    	if (isWall(x, y))
    	{
    		if (!isWall(x + 1, y) && !isWall(x - 1, y) && !isWall(x, y + 1) && !isWall(x, y - 1)) // alone  o
    		{
    			setDecorUp(x, y, 48);
    			setReal(x, y, 64);
    		}
    		
    		if (!isWall(x + 1, y) && isWall(x - 1, y) && !isWall(x, y + 1) && !isWall(x, y - 1)) // end L
    		{
    			setDecorUp(x, y, 77);
    			setReal(x, y, 93);
    			
    			//setDecorUp(x, y, 4);
    			//setReal(x, y, 20);
    		}
    		
    		if (isWall(x + 1, y) && !isWall(x - 1, y) && !isWall(x, y + 1) && !isWall(x, y - 1)) // end R
    		{
    			setDecorUp(x, y, 76);
    			setReal(x, y, 92);
    			
    			//setDecorUp(x, y, 4);
    			//setReal(x, y, 20);
    			
    		}
    		
    		if (!isWall(x + 1, y) && !isWall(x - 1, y) && !isWall(x, y + 1) && isWall(x, y - 1)) // end T
    		{
    			setDecorUp(x, y, 11);
    			setReal(x, y, 27);
    		}
    		
    		if (!isWall(x + 1, y) && !isWall(x - 1, y) && isWall(x, y + 1) && !isWall(x, y - 1)) // end B
    		{
    			setDecorUp(x, y, 43);
    			setReal(x, y, 59);
    		}
    		
    		if (isWall(x + 1, y) && isWall(x - 1, y) && !isWall(x, y + 1) && !isWall(x, y - 1)) // horizontal -----
    		{
    			setDecorUp(x, y, 4);
    			setReal(x, y, 20);
    		}
    		
    		if (!isWall(x + 1, y) && !isWall(x - 1, y) && isWall(x, y + 1) && isWall(x, y - 1)) // vertical |
    		{
    			setReal(x, y, 34);
    		}
    		
    		if (isWall(x, y + 1) && isWall(x + 1, y) && !isWall(x, y - 1) && !isWall(x - 1, y)) // corner TL
    		{
    			setDecorUp(x, y, 39);
    			setReal(x, y, 55);
    		}
    		
    		if (isWall(x, y + 1) && isWall(x - 1, y) && !isWall(x, y - 1) && !isWall(x + 1, y)) // corner TR
    		{
    			setDecorUp(x, y, 38);
    			setReal(x, y, 54);
    		}
    
              ......
           }
    .......
           }
    
    

    The final picture looks like this: https://img.itch.io/aW1hZ2UvODM3OTQvMzk0OTk2LnBuZw==/original/MVuubi.png



  • @starry-abyss
    Homemade auto tiling?
    Doesn't FlxTileMap already have that or your top down map only works using custom auto tiling?



  • @DleanJeans We had a lot of special cases, that should override general solution in some places, also some cross-tilemap stuff. But maybe you can achieve this with stock one somehow?



  • Thanks for the help so far guys. I appreciate it! ^^

    @Ali-Hassan said in Tile 0 Next to Tile 32?:

    I think a for loop could do the trick here.. something like

    for (j in 0...map.heightInTiles)		
    	for (i in 0...map.widthInTiles-1)		
    		if(map.getTile(i,j) == 0 && map.getTile(i+1,j) == 32)
    			map.setTile(i,j,newIndex,true);
    

    if you more complex checks you should probably check this tutorial.

    Sorry for the long time no post. But I tried to implement this doing:

    var newindex:Int = 1;
    
    for (j in 0...map.heightInTiles)
    	{
    		for (i in 0...map.widthInTiles - 1)
    		{
    			if (map.getTile(i, j) == 0 && map.getTile(i + 1, j) == 16)
    			{
    				map.setTile(i, j, newindex, true);
    			}	
    			//add(new Player(i, j));	
    		}		
    	}
    

    I switched the numbers to match what I had in my tile set. But either my tile set is not set up correctly. OR I wasn't doing something right. But otherwise I noticed no change.

    I was attempting to use it to achieve a look like this: http://opengameart.org/sites/default/files/styles/medium/public/dawnblocker_ortho_preview.png

    However, since obviously, I did not get what was going on with the snippet, I simply said 'forget it' and just used that tile set. Since that was the look I was trying to achieve.

    However, can you go through the snippet and explain what is supposed to happen? Since, I didn't see any relevant changes?

    Thanks again.



  • The code loops through the map as it increments by its tile size height and then width. It searches for a tile with an index of 0. if at the right side of that 0 there is a tile with an index of 16, then tile 0 will change to a tile with an index of 1. if that is not what you want then just map.setTile(i+1 to change the tile that has an index of 16 to a tile that has an index of 1.



  • All righty thank you! ^^


Log in to reply
 

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