Currently trying to keep my STI isometric map centered when increase the scale factor but can't quite get the math to check out.
Below is what i am doing to set my camera position (tx / ty);
-- Calculated each time the scale changes
tx = ((windowWidth - (map.width * map.tilewidth * scale)) / 2);
ty = ((windowHeight - (map.height * map.tileheight * scale)) / 2);
-- love.draw
map:draw(tx, ty, scale, scale);
This works fine for a scale factor of 1 but as i move, it almost curves. Not quiet sure what i'm missing from the calculation.
Any help greatly appreciated.
The most important factor is the position. We wanna move the screen around the position but the position is what it's all about.
So we start with that and add some more stuff. By default the upper left is the position. Down and towards the right is where the coordinates get larger so we do want to subtract some value to move the position from the upper left to the center.
Then we need to know how much area the screen covers. This is first and foremost the window itself. So we need the window size. But if we scale the viewport we scale how large one pixel should be displayed as. So we need to multiply the window size by scale.
Divide the window calculation by 2 to get the center and voila.