Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

Hey man I really can't thank you enough for showing me there was a problem with the scaling on Macs; not sure how I ever would have known. Posting a little code snippet here for anyone else using mouse positions in case Google brings them to this corner of the internet while fighting with WebGL and Retina displays. Technically it could work for any tile-based game to easily say what tile (or even pixel on a low-res game like this) the mouse is over. Thank you!!!

Position WhatTileIsMouseIn() {
    Vector2 mousePos = Input.mousePosition;
    mousePos = new Vector2 (mousePos.x, mousePos.y);
    float scaledMouseX = ((mousePos.x / Screen.width)) * 8; // the 8 here is how many tiles across your screen has
    float scaledMouseY = ((mousePos.y / Screen.height)) * 8 - 1; // the 8 is vertical tiles, minus 1 for the bottom border in my game
    return new Position((int)scaledMouseY, (int)scaledMouseX); // casting the floats to integers truncates them
}