2012-04-08 80 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

不要试图旋转世界 - 这是不可能的。相反,改变你的观点。