好吧,所以这是我的问题。
我一直在尝试在XNA中创建一种视觉日/夜循环,其中我有一个更新并保留时间的基础类和一个基于类更新时间输出背景的Sky类。
我无法弄清楚的是如何使月球/太阳以一个弯曲的向上弧线移动,该弧线跨越屏幕,基于一天中的什么时间。最有问题的部分是让Y轴曲线化,而X轴随着时间的推移而移动。
任何可以帮助我的人吗?
编辑: 好吧,看起来像Andrew Russels的例子帮我做了我需要做的事情。 虽然我不得不精力充沛,但我终于找到了合适的解决方案: float Time =(float)Main.inGameTime.Seconds /(InGameTime.MaxGameHours * 60 * 60/2);
this.Position.X = Time * (Main.Viewport.X + Texture.Width * 2) - Texture.Width;
this.Position.Y = Main.Viewport.Y - (Main.Viewport.Y * (float)Math.Sin(Time * MathHelper.Pi) / 2) - (Main.Viewport.Y / 2) + 50;
答案 0 :(得分:2)
尝试查看Math.Sin
或Math.Cos
函数。这些是您正在寻找的trigonometric functions。
这样的事情(给SpriteBatch
的位置):
float width = GraphicsDevice.Viewport.Width;
float height = GraphicsDevice.Viewport.Height;
float time = 0.5f; // assuming 0 to 1 is one day
Vector2 sunPosition = new Vector2(time * width,
height - height * (float)Math.Sin(time * width / MathHelper.TwoPi));
(免责声明:我尚未测试此代码。)
答案 1 :(得分:0)
还有Curve类。