c# - 在 XNA/C# 中添加自定义光标?

标签 c# .net xna mouse-cursor

我目前正在使用 XNA 开发游戏。我想在游戏中添加一个光标(不是标准的 Windows 光标)。我已经将 Sprite 添加到我的内容文件夹中。我有找到鼠标位置的方法,但我不知道应该如何在窗口中显示光标。

这是我用来查找鼠标位置的方法(我在 Game1 类的开头实例化了一个“MouseState”类):

public int[] getCursorPos()
    {
        cursorX = mouseState.X;
        cursorY = mouseState.Y;

        int[] mousePos = new int[] {cursorX, cursorY};
        return mousePos;
    }

最佳答案

为光标图像加载一个 Texture2D 并简单地绘制它。

class Game1 : Game 
{
  private SpriteBatch spriteBatch;

  private Texture2D cursorTex;
  private Vector2 cursorPos;


  protected override void LoadContent() 
  {
    spriteBatch = new SpriteBatch(GraphicsDevice);
    cursorTex = content.Load<Texture2D>("cursor");
  }

  protected override Update(GameTime gameTime() {
    cursorPos = new Vector2(mouseState.X, mouseState.Y);
  }

  protected override void Draw(GameTime gameTime)
  {
    spriteBatch.Begin();
    spriteBatch.Draw(cursorTex, cursorPos, Color.White);
    spriteBatch.End();
  }
}

关于c# - 在 XNA/C# 中添加自定义光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5371657/

相关文章:

C#/VB.Net - 枚举路径

c# - C# 中的 Listview 慢刷新

c# - 为什么 Trace.WriteLine 打印随机字符而不是指定的字符?

c# - 没有瓷砖 XNA 的 2D 游戏中的碰撞检测

xml - Linq-Xml [DirectoryNotFound或NullReferenceException]

c# - 如何在 asp.net mvc 5 的 editorforfield 中只允许输入正数

c# - 在 Unity3d 中为 VR 360 度图像应用更改聚焦球体的 Material

c# - 无法转换类型为 'Microsoft.Office.Interop.Outlook.ApplicationClass' {00063001-0000-0000-C000-000000000046} HRESULT : 0x80040155 的 COM 对象

c# - 检查对象的类型是否来自特定的命名空间

c# - 2D Monogame : Rectangle collision detection, 边特定