Mouse only showing in a certain radius around point on character, can't get it to work correctly.

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

Recommended Posts

I've got a 2d clone of Minecraft I've started on in XNA 4.0 and I'm trying to get the mouse to show only when its within a certain radius of a predefined point on the character. Its sort of working, but seems to only be working on the bottom half of the circle so far.
If anyone wants to see what it looks like so far and try to help me out that would be great!
Here's a link to the file : http://dl.dropbox.co...ith2DBlocks.zip

I'm currently using this to solve whether or not the mouse should be shown.
if (Math.Sqrt(Math.Pow((mouseY - headOriginY), 2) + Math.Pow((mouseX - headOriginX), 2)) < mouseViewDistance) { drawMouse = true; }

Once again, thanks to anyone that can help me with this, I'm having trouble concentrating today and I can't figure out what in the world its doing and why its showing up the way it is. I've spent the last couple hours just trying to figure out this one part.

Share on other sites
I believe the problem is in this code:

 headOriginX = bobX + 125; headOriginY = bobX + 124; 

In addition, I wouldn't use Math.Pow() for taking the square of a number. It's actually significantly faster to simply multiply them together:

 int deltaY = mouseY - headOriginY; int deltaX = mouseX - headOriginX; if (Math.Sqrt((deltaY * deltaY) + (deltaX * deltaX)) < mouseViewDistance) { drawMouse = true; } 
Another trick is to not use Math.Sqrt() (which is also pretty slow), and instead compare against the square of the mouseViewDistance, which you can precalculate. Not that your application is at the stage of needing optimisation, but it doesn't hurt to know which functions are kind of slow.

Share on other sites
Thank you so much, it always seems like the smallest errors are the hardest to fix. Thanks again for the optimization tips, I'll be sure to implement this asap. Then next is to finish character animations, then basic terrain generation, basic physics, and placing and destroying of blocks. Then I'll release an Alpha at that point.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633704
• Total Posts
3013460
×