【问题标题】:Objects depth sorting in isometric game等距游戏中的对象深度排序
【发布时间】:2014-01-30 23:48:24
【问题描述】:

我有等距平铺游戏引擎(菱形地图样式),我需要对我绘制的对象进行排序。我的对象是 1x1、2x1、4x2。如何根据此代码进行操作?

for (int osaY = 0; osaY < mapSize; osaY++)
        {
            for (int osaX = 0; osaX < mapSize; osaX++)
            {
                int x = osaX * 32;
                int y = osaY * 32;

                PlaceObject(thisObject, CartToIso(new Vector2(x, y)), new Vector2(osaX, osaY));
            }
        }

【问题讨论】:

  • 我不确定您显示的代码有何影响,但通常您可以完全根据视口的 Y 轴绘制等距场景,首先绘制较高的项目。您可能也有图层,但在一个图层内,这应该保持不变。只有当你有海拔时它才会变得困难,但这也可以被视为层。
  • 你试过什么?你有截图吗?代码打算做什么?

标签: c# xna monogame isometric tile-engine


【解决方案1】:

我如何解决排序问题:
1.创建IDisplay接口,并将其添加到处理显示Draw(SpriteBatch batch)的每个类中
2. 创建一个DisplayManager,它具有AddRemoveDraw 方法和任意数量的layers(IDisplay 对象列表)。就个人而言,中间层是我整理我的东西的层。所以我可以把东西放在排序的对象后面,放在排序的对象之前。
3.在处理绘图的Main类中,调用DisplayManager's Draw函数,该函数将遍历layers(Lists)和IDisplay项目,并在每个项目上调用Draw函数。

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
DisplayManager.Draw(spriteBatch);
spriteBatch.End();

然后在 DisplayManager 中:

public static void Draw(SpriteBatch batch){
   for (i = 0; i < bottom.Count; i++)
   {
       bottom[i].Draw(batch);
   }
   //Gets the model from the IDisplay item, and then it's Y position, and orders
   //the sort layer(list) by that.
   sort = sort.OrderBy(o => o.getModel.Position.Y).ToList();
   for (i = 0; i < sort.Count; i++)
   {
       sort[i].Draw(batch);
   }
   for (i = 0; i < top.Count; i++)
   {
       top[i].Draw(batch);
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 2016-11-04
    相关资源
    最近更新 更多