XNA 2D 旋转精灵,具有相对旋转位置(月球着陆器排气装置)
我正在制作一个小型月球着陆器克隆,它工作得很好,现在我已经向着陆器添加了粒子效果,所以当推力接合时,粒子效果就会创建,就在我的飞船中间。
我希望发生的是创建粒子,其中船舶排气位于精灵上。这让我难住了。我知道我应该能够计算它,因为我都有旋转角度和当前位置,所以我应该能够获得 64x64 精灵中任何像素的旋转位置。
我对计算 Lander.exhaust.X 和 Lander.exhaust.Y 值感兴趣。谁能指出我正确的方向。
//这是代码的一部分,我确定我不需要全部:)
Lander.acceleration.X = Lander.acceleration.X * (0.01f * gameTime.ElapsedGameTime.Seconds); Lander.acceleration.Y = Lander.acceleration.Y * (0.01f * gameTime.ElapsedGameTime.Seconds);
Lander.velocity.Y = Lander.velocity.Y + (0.05f + Lander.velocity.Y * gameTime.ElapsedGameTime.Seconds);
Lander.oldvelocity.X = Lander.velocity.X;
Lander.oldvelocity.Y = Lander.velocity.Y;
Lander.exhaust.X = (float)Math.Cos(Lander.RotationAngle) * 0.1f + Lander.Position.Y ;
Lander.exhaust.Y = (float)Math.Sin(Lander.RotationAngle) * 0.1f + Lander.Position.X ;
Lander.Position.Y = Lander.velocity.Y + Lander.Position.Y;
Lander.Position.X = Lander.velocity.X + Lander.Position.X;
//if (Lander.Position.Y >= groundlevel + (Lander.mSpriteTexture.Height / 2))
if (Lander.Position.Y >= groundlevel)
{
Lander.Position.Y = groundlevel;
Lander.velocity.X = 0f;
Lander.oldvelocity.X = 0f;
}
float circle = MathHelper.Pi * 2;
RotationAngle = RotationAngle % circle;
Lander.RotationAngle = RotationAngle;
RotationAngledegrees = MathHelper.ToDegrees(RotationAngle);
if (keyState.IsKeyDown(Keys.Space))
{
Lander.acceleration.X = (float)Math.Cos(Lander.RotationAngle) * 0.1f + Lander.acceleration.X;
Lander.acceleration.Y = (float)Math.Sin(Lander.RotationAngle) * 0.1f + Lander.acceleration.Y;
Lander.velocity.X = Lander.oldvelocity.X + Lander.acceleration.X;
Lander.velocity.Y = Lander.oldvelocity.Y + Lander.acceleration.Y;
particleEngine.EmitterLocation = new Vector2(Lander.exhaust.X, Lander.exhaust.Y);
-拉塞
I am making a little Lunar Lander clone, and its working quite ok, now i have added particle effects to the lander, so when the thrust is engange, the particle effect is created, just in the middle of my ship.
What i would like to have happen is that the Particles are created, where the ship exhaust is on the sprite. And this has me stumped. I know i should be able to calculate it, as i both have the rotation angle and the current location, so i should be able to get the rotated location of any pixel within my 64x64 sprite.
Im interested in calculating the Lander.exhaust.X and Lander.exhaust.Y values. Could anyone point me in the right direction.
//this is part of the code, im sure i dont need all of it :)
Lander.acceleration.X = Lander.acceleration.X * (0.01f * gameTime.ElapsedGameTime.Seconds);
Lander.acceleration.Y = Lander.acceleration.Y * (0.01f * gameTime.ElapsedGameTime.Seconds);
Lander.velocity.Y = Lander.velocity.Y + (0.05f + Lander.velocity.Y * gameTime.ElapsedGameTime.Seconds);
Lander.oldvelocity.X = Lander.velocity.X;
Lander.oldvelocity.Y = Lander.velocity.Y;
Lander.exhaust.X = (float)Math.Cos(Lander.RotationAngle) * 0.1f + Lander.Position.Y ;
Lander.exhaust.Y = (float)Math.Sin(Lander.RotationAngle) * 0.1f + Lander.Position.X ;
Lander.Position.Y = Lander.velocity.Y + Lander.Position.Y;
Lander.Position.X = Lander.velocity.X + Lander.Position.X;
//if (Lander.Position.Y >= groundlevel + (Lander.mSpriteTexture.Height / 2))
if (Lander.Position.Y >= groundlevel)
{
Lander.Position.Y = groundlevel;
Lander.velocity.X = 0f;
Lander.oldvelocity.X = 0f;
}
float circle = MathHelper.Pi * 2;
RotationAngle = RotationAngle % circle;
Lander.RotationAngle = RotationAngle;
RotationAngledegrees = MathHelper.ToDegrees(RotationAngle);
if (keyState.IsKeyDown(Keys.Space))
{
Lander.acceleration.X = (float)Math.Cos(Lander.RotationAngle) * 0.1f + Lander.acceleration.X;
Lander.acceleration.Y = (float)Math.Sin(Lander.RotationAngle) * 0.1f + Lander.acceleration.Y;
Lander.velocity.X = Lander.oldvelocity.X + Lander.acceleration.X;
Lander.velocity.Y = Lander.oldvelocity.Y + Lander.acceleration.Y;
particleEngine.EmitterLocation = new Vector2(Lander.exhaust.X, Lander.exhaust.Y);
-lasse
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要根据精灵的初始角度减去或加上
PI/2
角度,发射器将距离着陆器位置 32 像素。顺便说一句,将游戏的每个部分放在自己的类中可能是个好主意,这将使以后更改内容变得更加容易。
另一件事,当你将速度添加到位置时,你可以这样做:
它基本上做同样的事情。
You may have to subtract or add
PI/2
to the angle depending on the initial angle of the sprite the emitter will be 32 pixels away from the position of the Lander.On a side note, it would probably be a good idea to put each part of the game in its own class, it will make changing stuff later a LOT easier.
And another thing, when you add the velocity to the position, you can do this:
It basically does the same thing.