Note that there are some explanatory texts on larger screens.

plurals
  1. POTranslating screen location to isometric tile location with scaling
    primarykey
    data
    text
    <p>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?</p> <p>Here's the function that I'm using:</p> <pre><code> 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; } </code></pre> <p>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).</p> <p>Here's a screenshot in case that helps shed any light:</p> <p><img src="https://i.stack.imgur.com/MqF0K.png" alt="enter image description here"></p> <p><strong>Edit:</strong></p> <p>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.</p> <p>New function:</p> <pre><code> 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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload