私は練習中にこの問題に直面しましたが、ここでは解決策が見つかりました。これがあなたに役立つことを願っています。 XNA 4 Cシャープを使用。
宣言:anglecorrectionは、その角度「アップ」に向かってオブジェクトを移動するために必要とされること
Texture2D sprite;
Vector2 spritePosition = Vector2.Zero;
Vector2 spriteOriginalPos;
float spriterotation = 0;
float anglecorrection = (Math.PI * 90/180.0);
float speed = 1;
は注意してください。
ロード:
//Load basic texture to make it recognizable :)
sprite= Content.Load<Texture2D>("spritetexture");
//Default position in middle
spritePosition = new Vector2(
(graphics.GraphicsDevice.Viewport.Width/2) - (sprite.Width/2),
(graphics.GraphicsDevice.Viewport.Height/2) - (sprite.Height/2));
//Sprite centering
spriteOriginalPos.X = sprite.Width/2;
spriteOriginalPos.Y = sprite.Height/2;
更新:
if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Up))
{
spritePosition.X += speed * (float)Math.Cos(spriterotation - anglecorrection);
spritePosition.Y += speed * (float)Math.Sin(spriterotation - anglecorrection);
}
ドロー:
spriteBatch.Draw(sprite, spritePosition, null, Color.Black, spriterotation, spriteOriginalPos, 1.0f, SpriteEffects.None, 0f);
あなたのコードは、私には正常に見える(しかし、私は非常に疲れています!)。 'player.model.Position'を設定する前に、' Vector2.Multiply(unitV、player.model.Speed)*(float)gameTime.ElapsedGameTime.TotalSeconds'の実際の値は何ですか? – spender
http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2d.php – phadaphunk
ありがとう、私はそれを他の方法でやった –