我有你的解决方案。首先,你创建参数:
MouseState nowMouseState, lastMouseState;
在加载内容()中:
lastMouseState = Mouse.GetState();
创建一个函数:
public void ChangeState()//I check button have position:Vector2(0,0) and hight= width=100
{
nowMouseState= Mouse.GetState();//click
if (Mouse.GetState().X>0&&Mouse.GetState().X<100
&&Mouse.GetState().Y>0&&Mouse.GetState().Y<100
&&nowMouseState.LeftButton==ButtonState.Pressed
&&lastMouseState.LeftButton==ButtonState.Released)
{
if (Button_Tile)
Button_Tile=false;
else
Button_Tile= true;
lastMouseState = nowMouseState;//click
}
if (Mouse.GetState().LeftButton==ButtonState.Released)
{
lastMouseState = Mouse.GetState();
}
}
然后您可以将 ChangeState() 放入 Update() 中。