Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:20:24+00:00 2026-06-17T16:20:24+00:00

I’m attempting to translate the mouse’s location on the screen to a specific tile

  • 0

I’m attempting to translate the mouse’s location on the screen to a specific tile on the map. Using the function below, I believe I’m along the right lines however I can’t get it to scale correctly when I zoom. Any ideas why?

Here’s the function that I’m using:

    Vector2 TranslationVectorFromScreen(Vector2 toTranslate)
    {
        Vector2 output = new Vector2();

        toTranslate -= offset; // Offset is the map's offset if the view has been changed

        toTranslate.X /= tileBy2; // tileBy2 is half of the each tile's (sprite) size
        toTranslate.Y /= tileBy4; // tileBy2 is a quarter of the each tile's (sprite) size

        output.X = (toTranslate.X + toTranslate.Y) / 2;
        output.Y = (toTranslate.X - toTranslate.Y) / 2;

        return output;
    }

According to my debug information, the X and Y are incrementing when I move the mouse along the tile lines, however their values are all wrong because the scale is not being factored in. I’ve tried including the scale in the function above, but wherever I add it, it just seems to make matters worse. For reference, the scale is stored as a float where 1.0f means there is no scaling (just in case this is relevant).

Here’s a screenshot in case that helps shed any light:

enter image description here

Edit:

By changing the function to the below, the number still seem to increment at the same points (i.e. go up by 1 or down by 1 along the relevant axis per tile), however the results still seem to scale too much. For example, if the results are 100, 100, when I zoom in, these might change to 50, 50 even if the mouse is over the same tile.

New function:

    Vector2 TranslationVectorFromScreen(Vector2 toTranslate)
    {
        Vector2 output = new Vector2();

        toTranslate -= offset;

        toTranslate.X /= (tileBy2 * scale); // here are the changes
        toTranslate.Y /= (tileBy4 * scale); // 

        output.X = (toTranslate.X + toTranslate.Y) / 2;
        output.Y = (toTranslate.X - toTranslate.Y) / 2;

        return output;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:20:25+00:00Added an answer on June 17, 2026 at 4:20 pm

    After a bit of messing around with the code, I appear to have found a solution. I’ll leave it here in case it’s of use for anyone else:

        Vector2 TranslationVectorFromScreen(Vector2 toTranslate)
        {
            Vector2 output = new Vector2();
            Vector2 tempOffset = offset; // copy of the main screen offset as we are going to modify this
    
            toTranslate.X -= GraphicsDevice.Viewport.Width / 2;
            toTranslate.Y -= GraphicsDevice.Viewport.Height / 2;
            tempOffset.X /= tileBy2;
            tempOffset.Y /= tileBy4;
    
            toTranslate.X /= tileBy2 * scale;
            toTranslate.Y /= tileBy4 * scale;
    
            toTranslate -= tempOffset;
    
            output.X = (toTranslate.X + toTranslate.Y) / 2;
            output.Y = (toTranslate.X - toTranslate.Y) / 2;
    
            output += new Vector2(-1.5f, 1.5f); // Normaliser - not too sure why this is needed
    
            output.X = (int)output.X; // rip out the data that we might not need
            output.Y = (int)output.Y; // 
    
            return output;
        }
    

    I’m not entirely sure why the normaliser needs to be there, but I’ve played around with the scales and the size of the map in total and this doesn’t appear to affect what this value needs to be.

    Finally, here’s a screenshot to illustrate it working in the top left:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.