0

在下面的代码中,我为播放器使用了两个纹理。一个是它的正常动画,另一个是它的跳跃动画。在跳跃时使用以下代码运行时,只有少数帧运行并非全部。

public void draw(Object sender,GameTimerEventArgs e) 
{
        jumpframe++;

        if (jumpframe > 32)
        {
            jumpframe = 0;
        }

        TouchPanel.EnabledGestures = GestureType.Tap;
        TouchCollection touches = TouchPanel.GetState();
        if ( touches.Count >0)
        {
            touch = true;
            jump();
            System.Diagnostics.Debug.WriteLine("touch");
        }
        else if (touches.Count == 0)
        {
            playerr();
            System.Diagnostics.Debug.WriteLine(currentframe);
            touch = false;
        }
        spriteBatch.Draw(Texture.player[currentframe], Texture.position, Color.White);
        spriteBatch.Draw(Texture.jumpplayer[jumpframe], Texture.jumpposition, Color.White);

        currentframe++;
        if (currentframe > 24)
        {
            currentframe = 0;
        }

        System.Diagnostics.Debug.WriteLine(jumpframe);
        spriteBatch.End();
        // TODO: Add your drawing code here
    }

    public void jump()
    {
            Texture.jumpposition.X = 10;
            Texture.jumpposition.Y = 243;
            Texture.position.X = -200;
            Texture.position.Y = 243;
    }

    public void playerr()
    {
        Texture.position.X = 10;
        Texture.position.Y = 243;
        Texture.jumpposition.X = -400;
        Texture.jumpposition.Y = 243;
    }

}

4

1 回答 1

1

如果jumpframe增加并Texture.jumpplayer[jumpframe]正确扫描我认为您的问题在Texture.jumpposition定义中。

只是一个建议:在您的方法中检测触摸Update,而不是在 中Draw,该方法应仅用于绘图说明。

于 2013-10-09T15:04:56.997 回答