Adding a custom cursor in XNA / C #?

I am currently developing a game in XNA. I would like to add a cursor to the game (and not standard Windows). I already added a sprite to the content folder. I have a method for finding the position of the mouse, but I do not know how I need to display the cursor in the window.

Here is the method I use to find the mouse position (I created an instance of the "MouseState" class at the beginning of the Game1 class):

public int[] getCursorPos() { cursorX = mouseState.X; cursorY = mouseState.Y; int[] mousePos = new int[] {cursorX, cursorY}; return mousePos; } 
+4
source share
3 answers

Download Texture2D for the cursor image and just draw it.

 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(); } } 
+15
source

If you like downloading Windows Cursor (ani, cur), you can see: http://allenwp.com/blog/2011/04/04/changing-the-windows-mouse-cursor-in-xna/

+5
source

you can also use the graphical interface and manually load the Windows cursor to replace the default cursor

+1
source

Source: https://habr.com/ru/post/1344502/


All Articles