我目前正在XNA开发游戏。我想在游戏中添加一个游标(不是标准的Windows游标)。我已经将精灵添加到我的内容文件夹中。我有一个查找鼠标位置的方法,但我不知道如何在窗口中显示光标。
这是我用来查找鼠标位置的方法(我在Game1类的开头实例化了一个“MouseState”类):
public int[] getCursorPos()
{
cursorX = mouseState.X;
cursorY = mouseState.Y;
int[] mousePos = new int[] {cursorX, cursorY};
return mousePos;
}
答案 0 :(得分:15)
为光标图像加载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();
}
}
答案 1 :(得分:5)
如果您想加载Windows光标(ani,cur),您可以看到: http://allenwp.com/blog/2011/04/04/changing-the-windows-mouse-cursor-in-xna/
答案 2 :(得分:1)
您也可以使用GUI并手动加载Windows光标来替换默认光标