LibGdx 多层次等距

LibGdx Multi-level isometric

我对 Libgdx 和游戏编程真的很陌生...这是我的爱好

我已经下载了一些非常简单的城市游戏的图片。建个"one layer"图很简单(Drawing Isometric game worlds),

来了: an "eaxmple" for using a collection of images! 但是正如您在图像上看到的那样,有一个背景(蓝色)......然后有这些高层建筑(红色)。所以它们都是多层次的并且非常适合......所以我的问题是:什么是最好的构建这样的东西的方法还是它们有任何渲染模式?如何以不同的高度步长显示瓷砖??例如一座桥(例如 TheoTown)??

an image example

尝试按 z-index 对建筑物进行排序。在这种情况下,这意味着靠近屏幕底部的建筑物(无论其高度如何)应该最后绘制。

这是我会做的一个例子:

public class Building implements Comparable<Building> {
    //render, constructor, etc.
    public int compareTo(Building b) {
        return b.y - y;
        //sort buildings based on their distance from the bottom of the world
    }
}

在您的渲染代码中,首先对建筑物列表进行排序,然后绘制:

Collections.sort(listOfBuildings);
for (Building b : listOfBuildings) {
    b.render();
}

希望对您有所帮助! 顺便说一句,我现在无法对此进行测试,因此绘图可能会完全向后,即顶部的建筑物先于下方的建筑物绘制。如果是这样,请使用 compareTo 方法。