Graphics Libgdx:如何在具有动态尺寸的平铺贴图周围绘制圆形边框?

Graphics Libgdx:如何在具有动态尺寸的平铺贴图周围绘制圆形边框?,graphics,libgdx,border,Graphics,Libgdx,Border,在libgdx中,我有一个用不同单元格填充的平铺图: cell.setTile(new StaticTiledMapTile(reg1)); cell.setTile(new StaticTiledMapTile(reg2)); cell.setTile(new StaticTiledMapTile(reg...)); 其中reg是一个纹理区域 我提出: render = new OrthogonalTiledMapRenderer(map); render.setView(cam); ren

在libgdx中,我有一个用不同单元格填充的平铺图:

cell.setTile(new StaticTiledMapTile(reg1));
cell.setTile(new StaticTiledMapTile(reg2));
cell.setTile(new StaticTiledMapTile(reg...));
其中reg是一个纹理区域

我提出:

render = new OrthogonalTiledMapRenderer(map);
render.setView(cam);
render.render();
在整个游戏中,列数、行数和单元格大小都会有所不同,因此它们必须保持动态

现在,在这个平铺贴图周围,我想添加一个圆形边框。下面我用png展示了一些我计划如何做的例子:从左到右,首先是上边框,然后是右上角,然后是右边框。每个png文件都有方形尺寸

我想在下面实现的是缩放到平铺贴图右上角:

我计划使用这些PNG作为纹理区域,我可以在我的TileMap中设置为单元格,类似于:

    for (int x = 0; x < numcol+2; x++) {
            for (int y = 0; y < numrow+2; y++) {
                Cell cell = new Cell();                 

                if (y==numrow+1) {
                    cell.setTile(new StaticTiledMapTile(b_mid_top));
                }

                if (y==0) {
                    cell.setTile(new StaticTiledMapTile(b_mid_bottom));
                }
etc.
for(int x=0;x
我对png的尺寸有多个问题:正如我所提到的,在整个游戏中,单元格的大小可能会有所不同。据我所知,没有办法根据需要从png中调整单元格或纹理区域的大小。 所以我可以使用图像,动态调整它们的大小,将它们作为演员添加到舞台并绘制舞台,但我担心我可能会失去使用平铺贴图的好处。此外,我必须一方面处理舞台坐标,另一方面处理平铺贴图坐标,这听起来不是最好的方法

所以我有点迷路了! 在平铺地图周围绘制边界的最佳方法是什么?
我准备放弃我目前的任何想法,换一个更好的。我对Libgdx不是很有经验,如果我犯了一些愚蠢的错误,很抱歉。

我认为这个想法是好的。如果瓷砖大小改变,边框大小也会改变。你不能创建不同大小的瓷砖作为边框。如果你想创建始终相同的边框,你可以可以使用一个简单的带有大小的地图

创建如下内容:

NinePatch p = new NinePatch(texture, 5, 5, 5, 5); // the edge sizes are 5px here.
map = new TiledMap(); // the map with the bordercells
MapLayers layers = map.getLayers();
for (int l = 0; l < map1.getLayers().getCount(); l++) {
    // create a new layer which is bigger
    TiledMapTileLayer newlayer = new TiledMapTileLayer(
            ((TiledMapTileLayer) map1.getLayers().get(0)).getWidth() + 2,
            ((TiledMapTileLayer) map1.getLayers().get(0)).getHeight() + 2,
            (int) ((TiledMapTileLayer) map1.getLayers().get(0))
                    .getTileWidth(), (int) ((TiledMapTileLayer) map1
                    .getLayers().get(0)).getTileHeight());

    // now add the cells here
    for (int x = 0; x < newlayer.getWidth(); x++) {
        for (int y = 0; y < newlayer.getHeight(); y++) {
            //add the right tile regions here!
            if(x == 0 && y == 0){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(first edge));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == newlayer.getWidth()-1 && y == 0){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(second edge));
                newlayer.setCell(x, y, cell);
                continue;
            }
            if(x == 0 && y == newlayer.getHeight()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(third edge));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == newlayer.getWidth()-1 && y == newlayer.getHeight()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(fourth edge));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == 0){ 
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for bottom here));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(y == 0){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for first col));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == newlayer.getWidth()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for toprow));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(y == newlayer.getHeight()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for last col));
                newlayer.setCell(x, y, cell);
                continue;
            }
            //last but not least if none of this fit add the tile from the old map
            //dont forget the offsett
            newlayer.setCell(x, y, ((TiledMapTileLayer)map1.getLayers().get(l)).getCell(x-1, y-1)); //map1 is the original map without the borders
        }
    }
    layers.add(newlayer);
}
在渲染方法内部,您可以按tilemap的大小绘制它。您可以从贴图对象中选择大小:

p.draw(batch, 0, 0, tilesize*tilecountx, tilesize*tilecounty);
如果你不喜欢他的想法,你可以选择第二个版本。创建一个新的
Tilemap
,将boarder作为tile。你需要复制整个Tilemap,偏移量为1个tile(因为你需要1个tile空间),并创建一个新的Tilemap,其中包含2行和更多列

例如,应如下所示:

NinePatch p = new NinePatch(texture, 5, 5, 5, 5); // the edge sizes are 5px here.
map = new TiledMap(); // the map with the bordercells
MapLayers layers = map.getLayers();
for (int l = 0; l < map1.getLayers().getCount(); l++) {
    // create a new layer which is bigger
    TiledMapTileLayer newlayer = new TiledMapTileLayer(
            ((TiledMapTileLayer) map1.getLayers().get(0)).getWidth() + 2,
            ((TiledMapTileLayer) map1.getLayers().get(0)).getHeight() + 2,
            (int) ((TiledMapTileLayer) map1.getLayers().get(0))
                    .getTileWidth(), (int) ((TiledMapTileLayer) map1
                    .getLayers().get(0)).getTileHeight());

    // now add the cells here
    for (int x = 0; x < newlayer.getWidth(); x++) {
        for (int y = 0; y < newlayer.getHeight(); y++) {
            //add the right tile regions here!
            if(x == 0 && y == 0){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(first edge));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == newlayer.getWidth()-1 && y == 0){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(second edge));
                newlayer.setCell(x, y, cell);
                continue;
            }
            if(x == 0 && y == newlayer.getHeight()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(third edge));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == newlayer.getWidth()-1 && y == newlayer.getHeight()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(fourth edge));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == 0){ 
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for bottom here));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(y == 0){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for first col));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(x == newlayer.getWidth()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for toprow));
                newlayer.setCell(x, y, cell);
                continue;
            }

            if(y == newlayer.getHeight()-1){
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(textureregion for last col));
                newlayer.setCell(x, y, cell);
                continue;
            }
            //last but not least if none of this fit add the tile from the old map
            //dont forget the offsett
            newlayer.setCell(x, y, ((TiledMapTileLayer)map1.getLayers().get(l)).getCell(x-1, y-1)); //map1 is the original map without the borders
        }
    }
    layers.add(newlayer);
}
map=new tileMap();//带边框单元格的贴图
MapLayers layers=map.getLayers();
对于(int l=0;l
如果你真的有不同的瓷砖,我会为你的每一个瓷砖添加一个Bordertexture,以防你使用的是瓷砖贴图版本。如果你想调整
纹理的大小