基本上当我尝试创建OpenFileDialog时,通过单击“游戏”中的特定区域,即使我已经发布了鼠标,我的鼠标状态也会被“按下”。
OpenFileDialog dialog;
protected override void Update(GameTime gameTime)
{
if (selectSong.isClicked)
{
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
//code;
}
else
{
selectSong.isClicked = false;
// Disabling mouse event - because isClicked is always true after using showDialog()
}
}
UpdateMouse();
}
protected void UpdateMouse()
{
MouseState current_mouse = Mouse.GetState();
Console.Clear();
int mouseX = current_mouse.X;
int mouseY = current_mouse.Y;
selectSong.checkCollision(mouseX, mouseY, current_mouse.LeftButton);
exit.checkCollision(mouseX, mouseY, current_mouse.LeftButton);
Console.WriteLine("mouse X:" + mouseX + " mouse Y:" + mouseY);
Console.WriteLine("Left button down:" + current_mouse.LeftButton.ToString());
// Left button down - after creating Dialog.ShowDialog() is always pressed, even after releasing mouse, and hitting cancel in Dialog
}
以下是描述问题http://db.tt/NVnEUgLI
的屏幕截图答案 0 :(得分:0)
你的问题是,你在游戏窗口中按下鼠标,然后在openfiledialog中释放它。所以游戏窗口不再更新鼠标了。我认为你可以在鼠标释放后打开filedialog时解决这个问题。 为此你需要记住最后一帧的值:
MouseButton last_frame = MouseButton.Released;
protected void UpdateMouse()
{
MouseState current_mouse = Mouse.GetState();
Console.Clear();
int mouseX = current_mouse.X;
int mouseY = current_mouse.Y;
selectSong.checkCollision(mouseX, mouseY, current_mouse.LeftButton, last_frame);
exit.checkCollision(mouseX, mouseY, current_mouse.LeftButton, last_frame);
last_frame = current_mouse.LeftButton;
Console.WriteLine("mouse X:" + mouseX + " mouse Y:" + mouseY);
Console.WriteLine("Left button down:" + current_mouse.LeftButton.ToString());
// Left button down - after creating Dialog.ShowDialog() is always pressed, even after releasing mouse, and hitting cancel in Dialog
}
并在obj.checkCollision
上你需要输入
if(state_now == ButtonState.Released && state_last == ButtonState.Pressed &&...)
而不是
if(state_now == ButtonState.Pressed &&...)