XNA: Changing text that follows mouse cursor?

Started by
3 comments, last by danromeo 11 years, 8 months ago
Ok, I know this is a little wierd.

in XNA I want to create some changing text that positions with the mouse cursor. The mouse cursor is a custom .cur. The text will be a SpriteFont. If I create a Texture2D in a PictureBox and change the position to correspond with the mouse position in my HandleInput function the text drags behind the cursor when the cursor moves fast.....presumably because the mouse uses an interrupt and therefore draws more often than the game?. I need the changing text to behave as if it is part of the mouse cursor.

I'll bet if I find a way to slow the mouse draws down to the speed of the game draws the mouse behavior will become slower than a cashier in a downtown Montpelier Vermont Shaws grocery store. An animated cursor won't work because I'm trying to display floating point values....too many combinations. The only method I can think of that might work is to find a way to update the Texture2D as often as the mouse updates....which I have no clue how to do.

Any ideas on this?

THANKS.....as always.
Advertisement
I wrote a small "game" for my two-year-old that included hiding the windows mouse and drawing a new cursor (a Texture2D object drawn with SpriteBatch) at the mouse position with no lag at all, on a mid-range laptop. Can you post any code? My guess is something is horribly inefficient in the Update/Draw pair that's limiting your framerate or your Texture2D's position updates.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

I think when you hid the cursor and replaced it with a Texture2D that you effectively slowed your mouse updates down to the speed of the game updates. In this case the cursor performance might be unacceptably slow in a graphically intense game.

My saving grace here would be that this particular screen is not that graphically intense.....so you may be right. I'll give it a shot!
If the mouse updates slowed down, it was a negligible change, she could whip it back and forth with wild abandon and it would keep up (as would a cloud of ~300 sprites orbiting the mouse point). Do you rebuild the Texture2D every frame? That could be one source of the slow draw rate, depending on the efficiency of the rebuild call. I ran into similar issues in my current level editor when I first implemented picking (I was calling some heavy algorithms 10-12 times more often than I thought, per frame).

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

It bears saying for others who may read this post that the above method is absolutely the wrong way to implement a custom cursor because the system cursor normally updates many times faster than the graphic device and your cursor will flash when your frame rate slows down.

In this case, because I require changing text to track the mouse cursor, it appears to be the only way to do it. For any normal type of custom mouse cursor, and even for cursors with 256 colors and animated cursors, THIS is the way to do it....changes the actual system cursor, rather than hiding it and replacing it with a graphic that displays many times slower: http://allenwp.com/blog/2011/04/04/changing-the-windows-mouse-cursor-in-xna/.

There is nothing "horribly inefficient" in my code. I'm simply trying to do something a little out of the ordinary.

This topic is closed to new replies.

Advertisement