Jump to content
  • Advertisement
Sign in to follow this  
genar

Questions about Autotiling []

This topic is 891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there !

Im developing a little Duengon crawler since a few months and finnaly i wanna to make my game look better using autotiling. I never did this before and my first few trys were horrible i wrote like thousands of lines and it didn't worked either . Im giving my game some depth using isometric tiles for the walls so it looks kinda 2d and 3d together.

So let's get back to the topic, my main Problem is that my current Autotiling System is very large and full of if else statements. I begin with the floor and check if there's a wall nearby and if there's of i place the right tile there. But sometimes it don't work mostly where the walls are crossing. What's the best way to start, and what should I check ? Should I check for walls or even for floor tiles ? Could anyone give me an example how I could implement Autotiling for Isometric duengons ?

To understand how my game looks like here's an very old Video :



As you can see there sometimes a few tiles which aren't fitting. Mostly as I said before on crossings... I also can show some Code but that would be a huge amount of lines :/

Thanks for your help and I hope someone is reading this ^^

Share this post


Link to post
Share on other sites
Advertisement

First and foremost. That demo is really nice. Like the attack feels like it has impact, the movement is just right. Really like it!

 

Second, maybe its just me but could you share how you draw your scene? I'm not terribly sure how I'd implement tiling without seeing how you draw stuff.

 

For instance, if you got a sort of matrix structure of tiles, you could just set the floor last, so do a loop with an "if (empty) { //set as floor }".

 

The tile itself, the texture, should be seamless, which means if you put one next to the other, it should look continuous. How are the levels defined? For example, if they're on a separate structure, it shouldnt be too hard to make a tiny editor that lets you paint tiles with floor textures, and then just send the tiles to render, which already will look seamless.

Share this post


Link to post
Share on other sites

Hey TheChubu !

 

First thanks for your reply and your praise ^^  Yeah sure :

 

So first some reading stuff, im using libgdx if that matter. I am using three different layers. First the brick background, than the normal wall layer and an other layer for the different parts of the wall like crossings. For creating the normal wall layer i do that :

for(int y = 0; y < copyOfMap.length; y++){
		  
		  for(int x = 0; x < copyOfMap[0].length; x++){
			  
			  if(copyOfMap[y][x] == 1 ||
				 copyOfMap[y][x] == 4 ||
				 copyOfMap[y][x] == 10){
					

					if(x < 49 && y < 49 && x > 0 && y > 0){
						
						
						
						// 0 = up, 1 = left, 2 = down, 3 = right
						boolean[] directions = new boolean[4];
						// 0 = right top corner, 1 = right bottom corner, 2 =  left top corner, 3 = left bottom corner
						boolean[] corners = new boolean[4];
						
						// got an under neighbour
						directions[2] = copyOfMap[((int) y)-1][(int) x] == 2  ; 
							
						// got an upper neighbour
						directions[0] = copyOfMap[((int) y)+1][(int) x] == 2;
							
						// got an left neighbour
						directions[1] = copyOfMap[((int) y)][(int) x-1] == 2;
											
						// got an right neighbour
						directions[3] = copyOfMap[((int) y)][(int) x+1] == 2;
						
						corners[0] = copyOfMap[y+1][x+1] == 2;
						
						corners[2] = copyOfMap[y+1][x-1] == 2;
							
						corners[3] = copyOfMap[y-1][x-1] == 2;
							
						corners[1] = copyOfMap[y-1][x+1] == 2;
						
						
						
						if(directions[3] && !directions[1] && !directions[2] && !directions[0]){
							
							if(!corners[0]){
								
								region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
			                    region.setRegion(0, 0, 32, 32);			                  
		
			                    wallLayer.add(region, ((x*100)+100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
								
							}
							else if(!corners[1]){
								
								region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
			                    region.setRegion(0, 64, 32, 32);
		
			                    wallLayer.add(region, ((x*100)+100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
								
							}

I hope you understand my code, so im looping through the floor tiles. Than im checking for each of them if the floor tile got neighbours which are walls, if yes do the stuff there. There much more if else statements but it would be too long to put them all in here. Because sometimes there problems with my Autotiling system i created a third layer for the problem tiles. This time im looping through the wall tiles and looks if the tile got an floor neighbour. That looks like so :: 

for(int y = 0; y < copyOfMap.length;y++){
		 
		 for(int x = 0; x < copyOfMap[0].length;x++){
			 
			 switch (copyOfMap[y][x]) {
			 
			case 2:
				
				if(y > 0 && x > 0 && y < 49 && x < 49){
				
					// 0 = up, 1 = left, 2 = down, 3 = right
					boolean[] directions = new boolean[4];
					// 0 = right top corner, 1 = right bottom corner, 2 =  left top corner, 3 = left bottom corner
					boolean[] corners = new boolean[4];
					
					// got an under neighbour
					directions[2] = copyOfMap[((int) y)-1][(int) x] == 2; 
						
					// got an upper neighbour
					directions[0] = copyOfMap[((int) y)+1][(int) x] == 2;
						
					// got an left neighbour
					directions[1] = copyOfMap[((int) y)][(int) x-1] == 2;
										
					// got an right neighbour
					directions[3] = copyOfMap[((int) y)][(int) x+1] == 2;
					
					corners[0] = copyOfMap[y+1][x+1] == 2;
					
					corners[2] = copyOfMap[y+1][x-1] == 2;
						
					corners[3] = copyOfMap[y-1][x-1] == 2;
						
					corners[1] = copyOfMap[y-1][x+1] == 2;
					
					
					
					
					
					if(directions[3] && directions[1] && !directions[0] && directions[2]){
						
						if(!corners[0] && !corners[1] && !corners[2] && !corners[3]){
							
							if(transformGrid[y-1][x] == 10){
								
								region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
			                    region.setRegion(64, 128, 32, 32);
			                    region.flip(true, false);
		
			                    wallLayer.add(region, ((x*100))/Box2dVars.UNIT, ((y*100))/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
			                    
							}
							else{
								
								region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
			                    region.setRegion(64, 128, 32, 32);
			                    region.flip(false, false);
		
			                    wallLayer.add(region, ((x*100))/Box2dVars.UNIT, ((y*100))/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
								
							}
							
						}

Normally there again much more if else statements, isnt there a easier way to implement autotiling into a game ? And am i doing autotiling right or are there some mistakes ? What could i do better ? :)

 

Thanks for your time and your help ! :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!