0

我创建了一个按钮图像并命名它Texture2D btn_play。它用于主菜单,我想按它来更改CurrentGameState.

我的变量:

    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    Texture2D Tex_Btn_play;
    Rectangle Rec_Btn_play;

    enum Menu
    {
        MainMenu,
        Playing,
        Exit,
    }

    Menu CurrentGameState = Menu.MainMenu;

Update方法:

protected override void Update(GameTime gameTime)
{
    // Allows the game to exit
    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        this.Exit();

    if (Rec_Btn_play = TouchLocationState.Pressed);
    // TODO: Add your update logic here

    base.Update(gameTime);
}

是错的if (Rec_Btn_play = TouchLocationState.Pressed);,我不知道为什么。请帮我解决这个问题。

4

1 回答 1

0

您需要找到触摸位置并检查矩形是否与该位置相交

TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation tl in touchCollection)
{
    if (tl.State == TouchLocationState.Pressed)
    {
        if (Rct_Btn_Play.Contains(new Point(tl.Position.X,tl.Position.Y))
        {
            //DoStuff
        }

    }
}
于 2013-05-04T21:20:45.473 回答