使用触摸板的XNA中的跳跃播放器

本文关键字:跳跃 播放器 XNA 触摸 | 更新日期: 2023-09-27 18:34:38

在下面的代码中,我为播放器使用了两种纹理。 是它的普通动画,另一个是它的跳跃动画。在运行时,只有少数帧在跳转时运行,而不是全部运行。

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;
    }

}

使用触摸板的XNA中的跳跃播放器

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

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