2012-04-08 76 views
1

我有一個XNA PROGRAMM繪製一個紋理旋轉的整體水平

enter image description here

繪圖的代碼看起來像的場(50×50):

namespace Village 
{ 
    public class DrawLogic 
    { 

     internal static void DrawCreatures(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Dictionary<string, Texture2D> creatureTextures, List<Creature> list, Coordinate current) 
     { 
      spriteBatch.Begin(); 
      foreach (var item in list) 
      { 
       Vector2 origin = new Vector2(0, 0); 
       if (item.Selected) 
       { 
        spriteBatch.Draw(creatureTextures["selected"], new Vector2((item.Coordinates.X * 32) - current.X, (item.Coordinates.Y * 32) - current.Y), new Rectangle(0, 0, creatureTextures["human"].Width, creatureTextures["human"].Height), Color.White, 0.0f, origin, 1f, SpriteEffects.None, 1f); 
       } 
       else 
       { 
        spriteBatch.Draw(creatureTextures["human"], new Vector2((item.Coordinates.X * 32) - current.X, (item.Coordinates.Y * 32) - current.Y), new Rectangle(0, 0, creatureTextures["human"].Width, creatureTextures["human"].Height), Color.White, 0.0f, origin, 1f, SpriteEffects.None, 1f); 
       } 
      } 
      spriteBatch.End(); 
     } 

     internal static void DrawObjects(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Dictionary<string, Texture2D> creatureTextures, List<IHarvestable> list, Coordinate current) 
     { 
      spriteBatch.Begin(); 
      foreach (var item in list) 
      { 
       Vector2 origin = new Vector2(0, 0); 

       spriteBatch.Draw(creatureTextures["tree"], new Vector2((item.Coordinates.X * 32) - current.X, (item.Coordinates.Y * 32) - current.Y), new Rectangle(0, 0, creatureTextures["tree"].Width, creatureTextures["tree"].Height), Color.White, 0.0f, origin, 1f, SpriteEffects.None, 1f); 

      } 
      spriteBatch.End(); 
     } 

     internal static void DrawMap(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Dictionary<string, Texture2D> worldTextures, Block[,] map, Coordinate current) 
     { 
      spriteBatch.Begin(); 

      for (int i = 0; i < map.GetLength(0); i++) 
      { 
       for (int j = 0; j < map.GetLength(1); j++) 
       { 
        if (map[i, j].GetType() == typeof(Grass)) 
        { 


         Vector2 origin = new Vector2(0, 0); 
         spriteBatch.Draw(worldTextures["grass"], new Vector2((i * 32) - current.X, (j * 32) - current.Y), new Rectangle(0, 0, worldTextures["grass"].Width, worldTextures["grass"].Height), Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 1f); 
        } 
       } 
      } 

      spriteBatch.End(); 
     } 
    } 
} 

我的問題IST現在,我如何旋轉整個地圖?

應該看起來像:

The first shape is how i looks now, and the second one is how it should look

我不知道什麼是最好的方式做到這一點。

我應該旋轉我的紋理的每個人,並把他們在正確的順序,還是有辦法旋轉整個水平?

我想如果我能夠旋轉整個關卡,我的生物的步行算法會更容易一些,因爲它與當前的算法不會有所不同。

另一種方式(旋轉每一個紋理)會更難......我想。

在此先感謝!

回答

1

我會這麼做的方法是在繪製地圖之前將旋轉矩陣應用於投影矩陣。您可以在XNA文檔here中看到一些小技巧。

如果你正在尋找一個等軸測投影(我認爲你實際上是在尋找),XNA資源上的圖塊引擎教程進入它here

雖然我不確定我會看到這會如何簡化您的「步行算法」,但旋轉顯示器僅用於視覺目的,並且不會影響幕後數據。你能進一步詳細瞭解爲什麼你認爲它會改變事情嗎?

+0

謝謝你的回答!我查看了這些鏈接,我認爲他們會幫助我很多! – Sunnygurke 2012-04-08 18:22:08

0

您可以使用重載方法spriteBatch.Begin(),它接受一個變換矩陣。您可以設置使用Matrix.CreateRotationZ()和Matrix.CreateTranslation創建的矩陣。通過乘以它們來組合它們。 如果您想旋轉某個點,則必須應用翻譯,將相關點重新定位到原點,旋轉並翻轉回來。

0

不要試圖旋轉世界 - 這是不可能的。相反,改變你的觀點。