I am making a game in microoft visual basic. It is virtually finished, but I am having a problem. When you hit the start button a timer is activated making the character in the game equal mouse position. The problem is that the character is not actually going to the mouse position. It appears a distance a way from the mouse usually down and to the right. The distance is not the same every time, so I can't just offset the position of the character. The character still follows the mouse as it is supposed to, but it stays the same distance away from the mouse the entire time. Any way to fix this?

Recommended Answers

'change this to whatever image you're using.
Dim RedPiece As New Bitmap(My.Resources.Red)

'set the cursor property to equal the new cursor, whenever you want to change it.
Dim RedCursor As Cursor
RedCursor = New Cursor(RedPiece.GetHicon)
Jump to Post

All 6 Replies

Re: Mouse Position 80 80

You'll have to show how you're finding the mouse position. Most likely the rectangle holding the image is much bigger than the image. You could try resizing the rectangle, or calculating the center of the image and use that as an offset.

One way to make the character appear to follow the mouse, is change the mouse cursor to the character image, thus the image is automatically centered on the cursor.

Re: Mouse Position 80 80

The picturebox the image is in is only 20,20 it is at least several hundred points off the mouse.

Re: Mouse Position 80 80

Setting the cursor to an image of the character is probably your best bet.

Re: Mouse Position 80 80

I'm sorry, but how exactly do you do that?

Re: Mouse Position 80 80
'change this to whatever image you're using.
Dim RedPiece As New Bitmap(My.Resources.Red)

'set the cursor property to equal the new cursor, whenever you want to change it.
Dim RedCursor As Cursor
RedCursor = New Cursor(RedPiece.GetHicon)
Re: Mouse Position 80 80

Thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.