我目前正在开发一款小游戏,因为我只有一些街区作为墙壁,我真的想实现自动平铺。但是怎么做呢?我没有找到它的任何教程,只有一个游戏制作者,但这不适用于java:/
我已经尝试找到一个街区的邻居,而不是改变它的风格,但我想我还需要寻找角落的邻居?是吗?
有没有人知道如何实施这样的机制? :)
------------- EDIT --------------
所以,生病看了一下wiki和Ze Rubeus的一些教程,认为它会被解决但是还有一个问题:
当一个区块碰到另一个区块时,它可以工作,但是当一个区块有四个区块时,它就不再工作了。 Normaly,当一个块被一个左邻居包围,一个正确的一个和一个在下面,也有一个左右底角,比它应该绘制另一个图像,你可以看到它在左右两部分.By方式,价值2是一堵墙。这就是我的所作所为:
//------------------------------------------------------------------
//--------------------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);
}
写得很清楚,所以如果你能看一下就好了:)只需忽略wallLayer.add和纹理内容。
度过美好的一天^^
答案 0 :(得分:1)
Libgdx没有为您自动生成切片的功能,相反,您必须实施自己的算法来执行此类操作。
我建议您阅读官方WIKI中的this部分,此处还有一个提供programmatically generates tilemap和 here 一个篦式导师的例子如何创建一个程序生成的地下洞穴系统,你可以实现LIBGDX。