使用触摸板在XNA中跳跃的球员

时间:2013-10-09 10:53:00

标签: c# xna

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

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

}

1 个答案:

答案 0 :(得分:1)

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

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

相关问题