Sign in to follow this  

XNA: Changing text that follows mouse cursor?

This topic is 1967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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, [i]per frame[/i]).

Share this post


Link to post
Share on other sites
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: [url="http://allenwp.com/blog/2011/04/04/changing-the-windows-mouse-cursor-in-xna/"]http://allenwp.com/blog/2011/04/04/changing-the-windows-mouse-cursor-in-xna/[/url].

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

Share this post


Link to post
Share on other sites

This topic is 1967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this