Camera
Learning paths through this topic
The view keeps scrolling after I switch to another window and come back
Hold a scroll key, switch to another program and release it there, and the game never hears the release. When you return the camera runs away on its own. The same happens with the mouse at the edge. Here is what the game must forget and when, so scrolling only happens when you really asked for it.
A big map stutters at the borders between loaded areas as chunks load and unload
Large maps are cut into pieces and only the ones near the camera are kept. If you load and unload at the same line, a camera resting on the border makes the game build and throw away the same piece again and again. Here is the rule with two distances, the order of loading and a limit per frame.
Health bars and selection rings become dots when zoomed out and giants when zoomed in
Small markers that belong to units must follow the zoom, but only partly. Scaled exactly with the world they vanish far away and swallow the screen up close. Here is the size rule with a floor and a ceiling, how thin lines stay thin, and why sizes should land on whole pixels.
Clicking the minimap jumps to the wrong place when the map is not the same shape
A small overview map that is wider or taller than the picture it shows has empty bands, and clicks or the little view frame go wrong near them. Here is how to place the map inside its box, turn a click into a spot on the real map, and draw the frame so it never leaves the map.
Tilting the 3D map down low shows the sky and the empty world beyond the edge
A low, nearly horizontal view of a strategy map looks dramatic, but it shows the horizon, the sky and the empty space past the map's edge, and the visible ground grows huge. Here is how far the view reaches for a given height and tilt, and a lower tilt limit that follows from it.
Arrows at the screen edge that point to an attack outside the picture
A battle on the other side of a large map goes unnoticed unless something at the edge of the screen points the way. Placing an arrow at the right spot on the border, also in the corners, is a small geometry problem that most first tries get slightly wrong. Here is the calculation.
Turning the view with the mouse swings the map away instead of around a spot
Turning and tilting a 3D map view should circle the spot at the middle of the screen, as if walking around a table. Rotating the camera on its own spot sweeps the whole map away. Here is how to describe the camera so that turning keeps the spot, with limits for tilt and a way back to a position.
After turning the view, the forward key moves the camera sideways
In a 3D map view the player can turn around and keep scrolling, and the keys should still mean forward, back, left and right as seen on the screen. Using the map's own axes breaks this after the first turn. Here is the small rotation that fixes it and how the speed should depend on height.
Panning crawls when zoomed out and races when zoomed in
A fixed scroll speed feels right at one zoom level and wrong at all others, because the same distance on the map covers very different amounts of screen. Here is what the speed should be measured in, how diagonals fit in, and the calculation your AI needs.
Clicking a hill or a tall block selects the tile behind it
In a slanted map view, high ground is drawn higher up on the screen, so the plain way of turning a click into a tile hits the flat tile behind it. Here is how to test each height level in turn, how to choose between several hits, and why the sides of a tower count too.
A second small camera view shows another place, and clicks in it hit the main map
A small window that shows a faraway base or a followed unit is a second camera, and the mouse must know which one it is over. Treating the whole screen as the main view sends clicks to the wrong place, and a drag that starts in the small window must not leak out. Here is the lookup and the rule for drags.
Pressing the rotate key twice quickly spins the view back or turns it the long way
The view turns in animated quarter steps, and a second press while it is still turning is where it goes wrong: it stops, reverses or spins almost a full circle. Here is how to let presses add up, what the game logic should use while the picture is mid-turn, and when to tidy up the numbers.