Turning Without Rotating: Directions, Turrets and Tracks for 2D Sprites
Nothing in Iron Sector is ever rotated on screen: every heading a tank can show is its own picture, rendered in advance. This lesson shows how the right picture is chosen, how a turret stays on its hull, why tracks and boots are driven by distance and how a 30 Hz simulation still moves smoothly, with the game's real numbers.
- directions: SD vehicles, HD hulls, HD turrets
- 16 · 32 · 64directions: SD vehicles, HD hulls, HD turrets
- units of travel per track cycle of a T-34
- 1.13units of travel per track cycle of a T-34
- simulation steps under a 60 or 120 Hz display
- 30 Hzsimulation steps under a 60 or 120 Hz display
- frames for one T-34 in the HD set, 192 in SD
- 480frames for one T-34 in the HD set, 192 in SD
Why we do not rotate a picture
A 2D engine can rotate a sprite in one line of code, and Iron Sector never does. Its sprites are rendered once from 3D models from a fixed camera, into an atlas, so each of them is not a shape but a photograph of a shape under a fixed camera and a fixed sun. Turn the photograph and the sunlit side of the tank turns away from the sun, the shadow on the ground swings round with it, and every pixel is resampled, so the crisp edges turn to mush.
The shape is wrong too. In this projection depth is drawn at half scale, so a tank seen from the side is long on the screen and the same tank facing the camera is short. A rotated image keeps its length whichever way it points. In the figure, the T-34's hull frame for a heading of 45° is turned 90° by the renderer and set beside frame 12, the baked picture of the heading it should have reached.
So nothing rotates. Every heading a unit can show is a separate picture, rendered in advance, and a tank turns by swapping pictures. The rest of this lesson is about how many pictures that takes, how the pieces of a vehicle stay together and how the motion still looks smooth.


The direction formula
Picking the picture is one formula. Take the unit's heading a in the screen (u, v) plane, subtract 45°, divide by the width of one sector, round to the nearest whole number and wrap the result into the range from 0 to n − 1, where n is the number of directions of the frame group. In the code it is called dirN, and every hull, turret and soldier goes through it.
The 45 comes from the camera of lesson 1. Headings in the simulation are measured in the screen plane, which is the world turned by the camera's yaw, but the pictures were rendered by world heading. Subtracting 45 undoes that turn. A worked case: a tank heading 100° with 16 directions. 100 − 45 = 55, divided by 22.5 is 2.44, rounded 2: frame 02. With 32 directions a sector is 11.25° and with 64 it is 5.625°, and the same heading lands in frame 05 and frame 10. The double modulo is there for negative angles: a heading of 0° gives −2, which wraps to frame 14.
One thing the formula does not do is mirror. Many sprite games draw 8 directions and flip 3 of them to save memory. Here the sun is baked into every frame from the upper left, so a mirrored tank would be lit from the upper right. Every direction is its own picture, and nothing in the renderer ever flips a sprite.
dirN(a, n) = ((round((a − 45) / (360 / n)) mod n) + n) mod n n = 16 → 22.5°, n = 32 → 11.25°, n = 64 → 5.625° a = 100°, n = 16: (100 − 45) / 22.5 = 2.44 → 2 a = 100°: n = 32 → 55 / 11.25 = 4.89 → 5; n = 64 → 55 / 5.625 = 9.78 → 10 a = 0°, n = 16: −45 / 22.5 = −2 → (−2 mod 16 + 16) mod 16 = 14

How many pictures
How many directions are enough depends on what the eye watches. In the standard set (SD) every vehicle and gun has 16 directions and every soldier 8. The high-definition set (HD) spends its budget unevenly. A hull gets 32 directions. A turret gets 64, because tracking a target is the rotation a player stares at, and at 16 steps a turret visibly snaps. The firing turret also has 64, so a shot never makes the gun jump to another direction. A wreck keeps 16, because wrecks do not turn, and aircraft get 32.
Infantry stays at 8 in both sets, which sounds stingy until you count. A rifleman's sheet holds 83 poses: walking, running, crawling, aiming, dying in three ways and so on. 83 poses times 8 directions is 664 frames for one kind of soldier. That is not the largest sheet in the game, but soldiers together are 28,688 of the 79,046 frames of the HD set, 36 %, and 46 % of the SD set, for men who are 8 × 21 pixels on screen.
Going to 16 directions would double all of that, and nobody would see the difference on a figure that small. A direction count is a budget, and it goes where the eye goes.
rifleman: 83 poses × 8 directions = 664 frames soldiers, HD: 28688 / 79046 = 36 %
| Frame group | SD | HD |
|---|---|---|
| Hull (× 6 track phases) | 16 | 32 |
| Turret | 16 | 64 |
| Firing turret (× 3) | 16 | 64 |
| Wreck | 16 | 16 |
| Towed gun | 16 | 32 |
| Aircraft | 16 | 32 |
| Infantry | 8 | 8 |

A turret on a hull
A tank is two sprites, a hull and a turret, and they have to stay joined as both turn. The turret's picture is centred on its pivot, the turret ring. The hull's picture has a ground anchor. So for every hull direction the renderer needs the screen offset from the anchor to the ring.
The ring sits at a known point in the model: for the T-34, 3 units forward, 0 to the side and 5.1 up. Rotate the forward and sideways part by the hull direction plus the camera's 45°, squeeze it to half as the projection does, lift it by the height times CE = cos 30° = 0.866 and multiply by 3.75 pixels per unit. For direction 0 that gives θ = 45° and X = Y = 2.12, and the mount comes out at (7.95, −12.59) pixels: about 8 to the right and 12.6 up. For direction 24 of 32 it is (7.95, −20.54).
The formula is run once per direction and stored as a table, and the table is indexed by the quantised direction, not by the true heading. That is the important part. The hull picture only exists in 16 or 32 headings, so the ring is drawn in only 16 or 32 places, and the turret must sit exactly on the drawn ring, not where a smooth heading would put it; otherwise it would float off the hull between two steps. Finally the turret is sorted half a pixel in front of its hull, so it never flickers behind it.
θ = d · 360/N + 45° X = px·cos θ − py·sin θ, Y = px·sin θ + py·cos θ mount[d] = [X · PPU, (Y · SE − pz · CE) · PPU], PPU = 3.75, SE = 0.5, CE = 0.866 T-34, pivot [3.0, 0, 5.1], d = 0: θ = 45°, X = Y = 2.12 → (7.95, −12.59) px d = 24 of 32: θ = 315°, X = 2.12, Y = −2.12 → (7.95, −20.54) px turret depth = hull depth + 0.5
![The T-34 in HD hull direction 24 of 32 with turret frame 48 of 64. The cross is the hull's ground anchor and the ring the turret's pivot; the table entry mount[24] = (7.95, −20.54) px joins them.](/_next/image?url=%2Fimages%2Ftutorials%2Fsprite-directions%2Fturret-mount.webp&w=3840&q=75)
Points on a turning body
The turret ring is one case of a general problem: a point that belongs to a body and turns with it. The muzzle of a gun, where the flash and the smoke start. The seats of a crew around a field gun. The tail of a tank, where its dust is thrown up. The side of the hull, where a crew climbs out.
All of them are written once in the model's own frame, so many units forward and so many to the right, and one small function, offUV, moves them to the screen plane. It rotates the offset by the body's heading minus 45°, then turns the result into screen coordinates with the two √2 formulas of lesson 1. A point one unit straight ahead of a body heading 45° lands at u = v = 0.71.
Whenever a gun turns, its crew is placed the same way, with the slots turned by the gun's aim, so the loader and the gunner walk round with it and stay at their stations. Nothing is animated by hand. The geometry carries them.
offUV(px, py, hdg): (wx, wy) = rotate((px, py), hdg − 45°) u = (wx − wy) / √2, v = (wx + wy) / √2 px = 1, py = 0, hdg = 45°: (wx, wy) = (1, 0) → u = v = 0.71

Tracks driven by distance
The hull has six track frames, and the obvious way to play them is by time, so many frames per second. That is wrong, and the reason is visible the moment a tank slows down: its tracks would keep racing while the tank crawls, and they would seem to slide over the ground.
Tracks are a belt on the ground, and they move exactly as far as the tank moves. So the frame is chosen by distance. The simulation keeps an odometer for every vehicle, and the phase is the odometer divided by the length of one track cycle, times six, rounded down and wrapped to six. For the T-34 one cycle is 1.13 units, so each track frame stands for about 0.19 units of travel. At 59.92 units on the odometer the phase is 5; at 62.44 it is 0.
A tank that crawls shows its tracks crawling. A tank that stops shows them stopped, on whatever phase it stopped, and nothing slides. A wheeled truck does the same with its wheels, and when it stands still it simply shows phase 0.
phase = floor(odometer / cycle · 6) mod 6 T-34: cycle = 1.1327 units, 1.1327 / 6 = 0.189 units per frame odometer 59.92: floor(59.92 / 1.1327 · 6) = floor(317.4) = 317, 317 mod 6 = 5 odometer 62.44: floor(330.75) = 330, 330 mod 6 = 0

Boots that do not slide
Soldiers follow the same rule. A walk cycle is 8 frames, and it would be easy to play it at a fixed rate. But a man who runs takes longer steps and more of them, and a man who crawls barely advances per cycle; at any fixed rate one of them would skate.
So each gait has a stride, the distance one cycle of 8 frames covers: a walking man 4.2 units, a running man 6.4, a crawling man 1.8 and a man carrying ammunition 3.6. The simulation counts the distance each soldier has moved, as a walk phase that becomes units when divided by 0.55, and the frame is that distance divided by the stride, times 8, wrapped to 8.
Double the speed and the legs go twice as fast, exactly as they should. Stop, and the feet stop. The whole battle is fought by men 8 by 21 pixels tall, and the one thing that makes them look alive is that their boots touch the ground where they step.
frame = floor(walkPh / 0.55 / stride · 8) mod 8 stride: walk 4.2 · run 6.4 · crawl 1.8 · carry 3.6 units per frame: 4.2 / 8 = 0.525 · 6.4 / 8 = 0.8 · 1.8 / 8 = 0.225 units

Firing
A shot is three pictures. When a gun fires, the renderer swaps in the firing turret: frame 0 for the first 0.07 seconds, frame 1 until 0.2 seconds, frame 2 until 0.4 seconds, and then the ordinary turret returns. The recoil, the barrel sliding back and forward, is inside those three pictures. Nothing is computed at run time: the gun was rendered recoiled.
At night the whole tank, hull and turret, is tinted a warm #ffe0b0 while frame 0 shows, so the flash lights its own vehicle. A mortar shows its flash for 0.15 seconds. A machine gun team flickers for 0.3 seconds, showing its firing frame on two simulation frames out of every three, which reads as a burst without a dozen pictures.
And one thing is missing on purpose: guns do not elevate on screen. A T-34's armour-piercing shell leaves the barrel at 662 metres per second, so even at 1000 metres it flies for 1.51 seconds, drops 11.2 metres, and the gun is raised by only about 0.64°. On the 9.5-unit barrel that moves the tip by 0.35 pixels at zoom 1, a third of a pixel. No pictures were spent on it.
dt = t − fireT: dt < 0.07 → 0, dt < 0.2 → 1, dt < 0.4 → 2, then the turret 1000 m / 662 m/s = 1.51 s, ½ · 9.81 · 1.51² = 11.2 m elevation ≈ 0.64° → tip of a 9.5-unit barrel: 0.35 px at zoom 1



Dying, throwing, loading
Not everything is driven by distance. Animations that happen in place run on time, each at its own rate. A soldier dies in one of three ways, chosen by his number (the id mod 3), at about 6 frames per second: 6.15 for the first variant, 5.71 for the second and 6.67 for the third. The last frame is held forever, because the body stays.
A grenade throw runs at 6.67 frames per second for 1.2 seconds. A loader at a gun works at 3.33 frames per second, a slow 2.4-second cycle, and the ammunition carrier moves at 9.3 frames per second for 2.5 seconds after each shot, then stops.
The rates look odd because each one is 8 frames spread over a round time: a death takes 1.3, 1.4 or 1.2 seconds, a load cycle 2.4. Most of them live in the sprite set's metadata, next to the frames, not in the code; the carry rate and the throw time are the exceptions.
variant = id mod 3 die: 8 / 1.3 s = 6.15 fps · dieb: 8 / 1.4 s = 5.71 fps · diec: 8 / 1.2 s = 6.67 fps load: 8 / 2.4 s = 3.33 fps

Crews, ghosts and aircraft
Three more things move. A gun crew is four men, each with a job and a pose of his own: a gunner at the sight, a loader, an ammunition carrier and a commander with binoculars. For 0.75 seconds after each shot all but the loader duck into cover; then the loader loads and the carrier carries.
A ghost is the opposite of an animation. When an enemy tank moves out of sight, the game keeps drawing its last known resting picture where it was last seen, at alpha 0.35 and tinted grey #9a9a9a, until someone sees the real one again. Lesson 10 is about that memory.
Aircraft are the one thing that leaves the ground. The Ju 87 dive bomber has 32 directions and four frame groups: flying, diving, pulling out and its shadow. The plane is drawn lifted by its altitude z with the height term of lesson 1. Its shadow stays on the ground, slides away from the sun by (2.64, −0.72) pixels per unit of altitude and fades with height: at the cruise altitude of 110 its alpha is 0.375, it never drops below a quarter, and when the plane pulls out at 18 it is back at the cap of 0.8.
plane: y − z · CE · PPU shadow: ground + z · (2.64, −0.72) px shadow α = clamp(1 − z / (cruise · 1.6), 0.25, 0.8) cruise = 110: z = 110 → 1 − 110 / 176 = 0.375; z = 18 → 0.90 → 0.8


Two clocks
Everything above moves in steps, and the steps come from a simulation that runs at exactly 30 steps per second. The display runs at 60 or 120 hertz. If the renderer drew the simulation's positions as they are, a tank would move only on every second display frame at 60 Hz, on every fourth at 120, and judder.
So the renderer keeps two poses per unit: the one before the last step and the one after. Each display frame it works out how far it is between steps, a number from 0 to 1 called alpha, and draws the unit at the previous pose plus alpha times the difference. On a steady 60 Hz display alpha is about 0.5 and 1 in turn; at 120 Hz it climbs in quarters. Angles blend the same way, always the shortest way round, so a turret aiming from 350° to 10° turns through 20°, not 340°.
When the game is paused, alpha is 1 and the picture is exactly the last step, which is what screenshots and replays need. And if the machine falls behind, the loop runs at most 10 steps in one frame and then drops the backlog, so a stall becomes a jump instead of a slow-motion crawl.
DT = 1/30 s pose = prev + (cur − prev) · alpha, alpha = min(1, ahead) 60 Hz: alpha ≈ 0.5, 1, 0.5, 1 … 120 Hz: 0.25, 0.5, 0.75, 1 … angle 350° → 10°: +20° steps per display frame ≤ 10, then the backlog is dropped
The render clock
Positions are interpolated, but what about a fire, or a smoke puff? They are not between two poses; they are animations on a clock. If that clock were the simulation's, a fire could only change on a simulation step, 30 times a second, however fast the display runs.
So the renderer has its own time: the simulation's time plus the fraction of a step that has passed since the last one, and unlike alpha that fraction is not capped at 1. Every effect reads this render clock, and the fires use it to blend from one frame into the next, which removed a stutter they had had since the first version. Lesson 9 tells that story in full.
renderTime = t + clock · DT clock = ahead (not capped), alpha = min(1, ahead)
Sprites in motion, briefly
This way of moving is as old as sprites. The action games of the early nineties drew their figures in 8 directions and mirrored 3 of them, because memory was the limit. In 1994 Donkey Kong Country showed that a 3D model rendered into sprite frames could look richer than anything drawn by hand on the same hardware, and that is the family this game belongs to.
The real-time strategy games of the mid and late nineties gave their tanks 16 or 32 headings and a turret drawn as a separate sprite, so the gun could track while the tank drove. Sudden Strike, in 2000, put that on a whole battlefield of realistic armour, and it is the game Iron Sector is modelled on. Iron Sector keeps that split, adds 64 headings to the turret and drives tracks and boots by distance. The ideas are old. The budget is bigger.
What it costs
Turning without rotating is paid for in pictures. One T-34 is 192 frames in the standard set and 480 in high definition: 32 hull directions times 6 track phases, 64 turrets, 64 firing turrets times 3, and 16 wreck directions in 2 variants. Lesson 2 showed how trimming and packing make that affordable. The mount table is 16 or 32 pairs of numbers, computed once.
At run time the price is tiny: one direction formula and one blend per entity per frame, and the copy of the simulation's state into the page, which takes a median of 1.2 to 1.6 milliseconds in a stress-test battle. In exchange nothing is ever resampled, the sun never moves, and a thousand units draw as fast as a thousand stickers.
Which is what they are.
SD: 16 × 6 + 16 + 16 × 3 + 16 × 2 = 96 + 16 + 48 + 32 = 192 HD: 32 × 6 + 64 + 64 × 3 + 16 × 2 = 192 + 64 + 192 + 32 = 480