简体   繁体   中英

Java/Libgdx auto tile

im currently developing a little game and because i only got some blocks as walls, i really wanna implement auto tiling. But how to do that ? I havent found any tutorials for it, just one for gamemaker, but that dont work on java :/

I already tried to find the neighbour of a block, than change the style of it, but i think i need to also look for the corner neighbours ? Is that right ?

Does anyone got an idea how to implement such a mechanic ? :)

-------------EDIT--------------

So, ill looked at the wiki and some tutorials of Ze Rubeus, thought it would be solved but theres one problem left :

墙问题

It works, when one block touches another, but soon as there's a block of four blocks, it wont work anymore. Normaly, when a block is surrounded by a left neighbour, a right one and one under, also got a corner with the right and left bottom, than it should draw an other image, you can see it in the left and right part.By the way, the value 2 is a wall. Here's what i did :

//------------------------------------------------------------------
                    //--------------------Checking for all sides------------------------
                    //------------------------------------------------------------------

                    // 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;

                    //------------------------------------------------------------------
                    //--------------------Checking for corners--------------------------
                    //------------------------------------------------------------------


                    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;





                    // Right
                    if(directions[3]){

                        if(directions[2]){

                            if(directions[1] && corners[1] && corners[3]){

                                region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                                region.setRegion(32, 0, 32, 32);

                                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(0, 0, 32, 32);

                                wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
                            }

                        }
                        else if(directions[0]){

                            region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                            region.setRegion(0, 64, 32, 32);

                            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(32, 0, 32, 32);

                            wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

                        }
                    }





                    // Left
                    else if(directions[1]){

                        if(directions[2]){

                            if(directions[3] && corners[1] && corners[3]){

                                region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                                region.setRegion(32, 0, 32, 32);

                                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(128, 0, 32, 32);

                                wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
                            }   

                        }
                        else if(directions[0]){

                            region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                            region.setRegion(128, 32, 32, 32);

                            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(32, 0, 32, 32);

                            wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
                        }

                    }





                    // Up
                    else if(directions[0]){

                        if(corners[2]){

                            region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                            region.setRegion(0, 32, 32, 32);

                            wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

                        }
                        else if(corners[3]){

                            region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                            region.setRegion(0, 32, 32, 32);

                            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(0, 32, 32, 32);

                            wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
                        }

                    }





                    // Down
                    else if(directions[2]){


                        region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
                        region.setRegion(0, 32, 32, 32);

                        wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);


                    }                       

Wrote it clearly, so it would be nice if you could look at it :) Just ignore the wallLayer.add and the texture stuff.

Have a great day ^^

Libgdx don't have a feature to auto generate tiles for you, instead you have to implement your owen algorithme to do this kind of stuff.

I suggest that you read this section in the official WIKI, also here is an exemple who provides a programmatically generates tilemap , and here a grate tutoriel on how to Create a Procedurally Generated Dungeon Cave System that you can implement to LIBGDX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM