0

最近、コードをアニメーション化されていないスプライトからアニメーション化されたものに変更しました。画像の角度に問題があります。

回転すると、火の玉が正しい方向に射撃しているため、角度が機能していることがわかりますが、アニメーション化されたスプライトは機能していません。メソッドでbase.Angleを使用してみましたSpriteBatch.Drawが、5つの引数を取りませんでした。

これは私のコードです:

class Dragon : MovingGameObj
{
    public Dragon()
    {
        framerate = 14;
        timetolive = 3000;
        repeat = 1;
        timer = 0;
        framesX = 1;
        framesY = 2;
        frameSize = 100;
        alive = true;
        activeframe = 0;
        MaxSpeed = 2.5F;
        FireballPower = 0;
        prevKs = Keyboard.GetState();
        prevKs2 = Keyboard.GetState();
        Life = 100F;
        Kills = 0;
        Angle = -(float)(Math.PI / 2);    
    }

    public bool alive;
    private int activeframe;
    int tmpTid = 0;
    public int framerate { set; get; }
    public int timetolive { set; get; }
    public int repeat { set; get; }
    public int framesX { set; get; }
    public int framesY { set; get; }
    public int timer { set; get; }
    public int frameSize { set; get; }
    public bool Enemy { get; set; }
    public float MaxSpeed { get; set; }
    public float FireballPower { get; set; }
    public int WeaponType { get; set; }
    public bool FireballFired { get; set; }
    public float Life { get; set; }
    public int Kills { get; set; }

    protected KeyboardState prevKs;

    protected KeyboardState prevKs2;
    public void Respawn()
    {
        Life = 100F;
        Random randomerare = new Random();
        Position = new Vector2(randomerare.Next(1000), randomerare.Next(1000));
        Angle = 0F;
    }

    public override void Update(GameTime gameTime)
    {
        KeyboardState ks = Keyboard.GetState();
        KeyboardState ks2 = Keyboard.GetState();
        #region Player 1
        if (Enemy == false)
        {
            if (ks.IsKeyDown(Keys.Up))
            {
                if (Speed < 0) Speed = 0;
                if (Speed < MaxSpeed) Speed = Speed * 1.005F + 0.01F;
                else Speed = MaxSpeed;
            }
            if (ks.IsKeyDown(Keys.Down))
            {
                if (Speed > -1.0F) Speed -= 0.04F;
                else Speed = -1.0F;
            } 
            if (ks.IsKeyUp(Keys.Down) && ks.IsKeyUp(Keys.Up) && Speed > 0)
            {
                Speed -= 0.01F;
                if (Speed <= 0) Speed = 0;
            }
            if (ks.IsKeyUp(Keys.Down) && ks.IsKeyUp(Keys.Up) && Speed < 0)
            {
                Speed += 0.01F;
                if (Speed >= 0) Speed = 0;
            }

            if (ks.IsKeyUp(Keys.Left))
            {
                Angle += 0.02F;
            }
            if (ks.IsKeyUp(Keys.Right))
            {
                Angle -= 0.02F;
            }
            if (ks.IsKeyDown(Keys.Space))
            {
                if (FireballPower < 100)
                    FireballPower += 0.5F;
                else
                    FireballPower = 100;
            }

            if (ks.IsKeyUp(Keys.Space) && prevKs.IsKeyDown(Keys.Space))
            {
                //FireballPower = 0;
                FireballFired = true;
            }
        }
        #endregion
        #region Player 2
        if (Enemy == true)
        {
            if (ks2.IsKeyDown(Keys.W))
            {

                if (Speed < 0) Speed = 0;
                if (Speed < MaxSpeed) Speed = Speed * 1.005F + 0.01F;
                else Speed = MaxSpeed;
            }
            if (ks2.IsKeyDown(Keys.S))
            {
                if (Speed > -1.0F) Speed -= 0.04F;
                else Speed = -1.0F;
            }
            if (ks2.IsKeyUp(Keys.S) && ks2.IsKeyUp(Keys.W) && Speed > 0)
            {
                Speed -= 0.01F;
                if (Speed <= 0) Speed = 0;
            }
            if (ks2.IsKeyUp(Keys.S) && ks2.IsKeyUp(Keys.W) && Speed < 0)
            {
                Speed += 0.01F;
                if (Speed >= 0) Speed = 0;
            }

            if (ks2.IsKeyUp(Keys.A))
            {
                Angle += 0.02F;
            }
            if (ks2.IsKeyUp(Keys.D))
            {
                Angle -= 0.02F;
            }
            if (ks2.IsKeyDown(Keys.LeftControl))
            {
                if (FireballPower < 100)
                    FireballPower += 0.5F;
                else
                    FireballPower = 100;
            }

            if (ks2.IsKeyUp(Keys.LeftControl) && prevKs2.IsKeyDown(Keys.LeftControl))
            {
                //FireballPower = 0;
                FireballFired = true;
            }
        }
        #endregion
        prevKs = ks;
        prevKs2 = ks2;

        Direction = new Vector2((float)Math.Cos(Angle), (float)Math.Sin(Angle));

        timer += gameTime.ElapsedGameTime.Milliseconds;
        if (timer > timetolive)
        {
            alive = false;
        }
        tmpTid += gameTime.ElapsedGameTime.Milliseconds;
        if (tmpTid > (1000 / framerate))
        {
            activeframe += 1;
            tmpTid = 0;
            if (activeframe > (framesX * framesY))
            {
                activeframe = 0;
            }
        }
        base.Update(gameTime);
    }

    public override void Draw(SpriteBatch spriteBatch)
    {
        Rectangle tmp = new Rectangle(activeframe%framesX*frameSize,activeframe/framesY*frameSize,frameSize,frameSize);
        spriteBatch.Draw(base.Gfx,base.Position, tmp,Color.White);
    }                 
}
4

1 に答える 1

0

このSpriteBatch.Draw()オーバーロードを使用してみてください:

spriteBatch.Draw(base.Gfx, base.Position, tmp, Color.White, Angle, Vector2.Zero, 1f, SpriteEffects.None, 0f);
于 2012-12-13T09:31:15.803 に答える