簡體   English   中英

僅當XNA未覆蓋窗口時,如何識別鼠標單擊/移動?

[英]How to recognize mouse clicks / movement only when window is not covered in XNA?

在XNA(MonoGame,FNA)中使用鼠標控件時,我使用類似以下方法:

    public static bool IsMouseClickedLeft()
    {
        // No clicks if game is not the active application
        if (Game.IsActive == false) return false;

        if (mouseState.LeftButton == ButtonState.Pressed) return true;
        return false;
    }

但是,在窗口模式(如果不是全屏模式)下,即使游戲窗口被其他窗口(例如瀏覽器或Windows文件瀏覽器)覆蓋或部分覆蓋,也會識別並處理鼠標單擊(和鼠標移動)。 如何確保僅識別鼠標單擊,即單擊了游戲窗口的可見(未覆蓋)部分。

if (ms.LeftButton == ButtonState.Pressed
&& _previousMouseState.LeftButton == ButtonState.Released
&& this.IsActive
&& ms.X >= 0 && ms.X < graphics.PreferredBackBufferWidth
&& ms.Y >= 0 && ms.Y < graphics.PreferredBackBufferHeight
&& System.Windows.Forms.Form.ActiveForm != null
&& System.Windows.Forms.Form.ActiveForm.Text.Equals(this.Window.Title)) {

//單擊鼠標,窗體處於活動狀態}

可以在http://www.systemroot.ca/2011/08/xna-check-if-a-click-is-on-the-game-form-window/找到

本質上,您正在檢查鼠標是否在屏幕內。 撰寫該帖子的這位先生還使用了自定義地圖編輯器,發現他還需要檢查活動表單,這是最后兩行的工作,以確保活動窗口確實是游戲窗口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM