2014-01-30 28 views
0

我有等角拼图游戏引擎(钻石图样式),我需要对物体进行排序。我的对象是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)); 
      } 
     } 
+0

我不知道如何代码你出的问题,但通常你可以绘制等距场景完全基于脱身视口的Y轴,首先绘制较高的项目。你也可能有图层,但在一个图层中,应该保持真实。如果你有海拔高度,它应该只会变得困难,但也可以被视为层。 – Magus

+0

你有什么尝试?你有截图吗?代码打算做什么? – craftworkgames

回答

0

如何解决分类法,:
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); 
    } 
}