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

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

这是我用来找到鼠标位置的方法(我在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("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(); } } 

如果你喜欢加载Windows光标(ani,cur),你可以看到: http : //allenwp.com/blog/2011/04/04/changing-the-windows-mouse-cursor-in-xna/

您也可以使用GUI并手动加载Windows游标来替换默认游标