Jump to content
  • Advertisement
Sign in to follow this  
JasonBradley

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.

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

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 this post


Link to post
Share on other sites
Advertisement
I believe the problem is in this code:


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

headOriginY is being calculated from bobX, instead of bobY.

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!