如何将图像照片用作Windows手机按钮

时间:2013-05-04 20:18:22

标签: xna windows-phone

我创建了一个按钮图像,并将其命名为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);错了,我不知道为什么。请帮我解决这个问题。

1 个答案:

答案 0 :(得分: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
        }

    }
}