简体   繁体   English

Java / Libgdx自动平铺

[英]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 :/ 我还没有找到任何针对它的教程,只是针对游戏玩家的,但是在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 : 因此,我看了Wiki和Ze Rubeus的一些教程,以为可以解决这个问题,但还有一个问题:

墙问题

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. 通常,当一个街区被一个左邻居,一个右邻居和一个在下的邻居包围时,它的右下角和左下角也有一个角,因此它应该绘制其他图像,因此您可以在左右部分看到它。顺便说一句,值2是一堵墙。 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. 清楚地写上它,这样就可以了:)只需忽略wallLayer.add和纹理内容。

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. Libgdx没有为您自动生成图块的功能,相反,您必须实现owen算法来执行此类操作。

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. 我建议您阅读官方WIKI中的节,这里还有一个示例 ,它提供了以编程方式生成的tilemap这里是一个炉排教程,介绍了如何创建可以生成为LIBGDX的程序生成的地牢洞穴系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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