C# XNA 鼠标位置

标签 c# xna

我在 XNA 中的鼠标坐标有一些问题 - 0x0 任意靠近(但不在)我屏幕的左上角。

我现在正在窗口模式下运行游戏,但坐标是基于屏幕的,而不是游戏窗口(尽管 XNA 文档告诉我它应该不是这样)

提前致谢!

代码如下:

namespace TheGame
{
   class Mousey
   {
      static public Vector2 pos;
      static private Texture2D tex;
      static public MouseState mouseState;
      static public MouseState previousState;

      //static public Mousey()
      //{
      //}

      static public void Update()
      {
         previousState = mouseState;
         mouseState = Mouse.GetState(); //Needed to find the most current mouse states.
         pos.X = mouseState.X; //Change x pos to mouseX
         pos.Y = mouseState.Y; //Change y pos to mouseY
      }

      //Drawing function to be called in the main Draw function.
      static public void LoadContent(ContentManager thecontent)
      {
         tex = thecontent.Load<Texture2D>("mousey");
      }

      static public void Draw(SpriteBatch batch) //SpriteBatch to use.
      {
         batch.Draw(tex, pos, Color.White); //Draw it using the batch.
      }

      static public bool LBP()
      {
          if (mouseState.LeftButton == ButtonState.Pressed && previousState.LeftButton ==                      ButtonState.Released)
          {
              return true; 
          }
          else 
          { 
              return false; 
          }
      }   
   }
}

最佳答案

在 game.cs 中:

//sets the windows mouse handle to client bounds handle

Mouse.WindowHandle = Window.Handle;

关于C# XNA 鼠标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7911124/

相关文章:

c# - 事件查看器 — 记录到子文件夹?

c# - 是否可以通过 COM 公开引用类型?

c# - 先知断言失败

c# - 构建 2D XNA 游戏引擎

multithreading - “current vertex declaration does not include all the elements required”

c# - IDictionary 到字符串

c# - 如何使用 SMO 创建本地数据库实例

c# - editorconfig - 无法使命名约定起作用

c# - 在简单的 2d 游戏中移动 Sprite 的速度比更新速度快的最佳方法是什么?

c# - XNA 不跳平台