1

基本上,当我尝试创建 OpenFileDialog 时,通过单击“游戏”中的特定区域,我的 mouseState 即使我已经释放它,也会保持“按下”状态。

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

4

1 回答 1

0

您的问题是,您在游戏窗口中按下鼠标,然后在 openfiledialog 中释放它。所以游戏窗口不再更新鼠标。我认为您可以在释放鼠标后打开文件对话框时解决此问题。为此,您需要记住最后一帧的值:

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 &&...)
于 2013-07-29T11:04:19.760 回答