Hi guys, i’m looking for some guidance on storing all the tiles in my game, highlight where the mouse hovers, and dealing with the resize of all this to make sure the mouse still highlights the correct tile.
So I usually make my games a fixed size but I feel like allowing users to resize as they wish and I plan on making an Android version that uses a Fit-viewport (keep the aspect ratio and put black bars around the game). I was thinking of storing my tiles inside an array and then doing the following code that will allow me to access the tile where the user is hovering their mouse and then drawing a texture at that position.
Tile currentTile = mapTiles[Gdx.input.getX()/32][Gdx.input.getY()/32];
batch.draw(Assets.highlightedTileTexture, currentTile.x(), currentTile.y )
Now here is my concern. This will work great for a fixed resolution as I’m simply getting the mouse location and then getting the tile position that the mouse is over, and the map is the same size as the screen. However, when I resize the screen all the coordinates will get messed up (I think) as I stored the tiles positions like so:
// For loop above that gets the tiles, cells and layer width/height
int tx = x * tileWidth:
int ty = y * tileHeight;
Due to my viewport trying to keep the same aspect ratio, there will be black bars either horizontally or vertically which means that the mouse might be over a blank spot on the screen coords and still highlight a tile.
I was thinking that maybe I could use the camera.unproject on the mouse position to solve this or some resize logic but i’m not sure. I could also be completely wrong on the whole thing but I’d rather think about this now than getting stumped by it when I’m creating the game.
Thanks