旋转整个标高 [英] Rotating the whole level

查看:31
本文介绍了旋转整个标高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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

我不确定这将如何简化您的"遍历算法",因为在这方面旋转显示仅用于视觉目的,不会影响幕后的数据。你能更详细地说明你认为这会改变事情的原因吗?

这篇关于旋转整个标高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆