Rotating the whole level(旋转整个标高)
本文介绍了旋转整个标高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XNA
程序,它绘制一个纹理的字段(50x50)
图形代码如下:
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();
}
}
}
我现在的问题是,如何旋转整个地图?
应该是这样的:
我不知道执行此操作的最佳方法是什么。
我应该旋转我的所有纹理并按正确的顺序放置它们,还是有办法旋转整个关卡?
我认为如果我可以旋转整个水平线,我的生物的行走算法会更容易,因为它和我现在的算法没有什么不同。
另一种方式(旋转每一个纹理)会困难得多。我想是的。
提前谢谢!
推荐答案
我的方法是在绘制地图之前对投影矩阵应用旋转矩阵。您可以在XNA文档here中看到一个小操作指南。
如果您正在寻找等轴测投影(我认为这正是您实际正在寻找的),请参阅XNA参考资料中的平铺引擎教程here。
我不确定这将如何简化您的"遍历算法",因为在这方面旋转显示仅用于视觉目的,不会影响幕后的数据。你能更详细地说明你认为这会改变事情的原因吗?
这篇关于旋转整个标高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:旋转整个标高


猜你喜欢
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01