2014-01-30 30 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); 
    } 
}