GameObject mouseObject;and load it up in LoadContent
mouseObject = new GameObject(Content.Load<Texture2D>("mouse"),
0,0,
new Rectangle(0,0,25,25));
Then in Update we can update it's position
MouseState ms = Mouse.GetState();Then simply call our custom drawing method in Draw
mouseObject.position.X = ms.X;
mouseObject.position.Y = ms.Y;
mouseObject.Draw(spriteBatch);
The only other thing that can be helpful here is if your mouse "hotspot" is not in the top left corner, you may want to add an offset value to your gameObject and then in your GameObject.Draw method, do position-offset for the image position. See the attached code sample to see what I did with that (it was an afterthought).
Now you should have your cursor drawn at your mouse's location. You could of course have various cursors in a spritesheet then simply change the source rectangle based on your need.
The source for this post
No comments:
Post a Comment