Skip to content
Game 0 Unit 8 of 15 1 hr learning time

Blitting

Stamping a shape is one thing; moving it is another. To animate a shape you redraw it each frame in a new place — and erase where it was, or it smears. Meet the Blit family, the no-trail trick, and why a shape must stay on its bitmap.

53% of Meet Blitz

Last unit you stamped a shape with Blit and it stayed put. A game needs it to move — and moving is trickier than stamping, because of what you leave behind. Blit a shape, shift it a few pixels, blit again, and you've now got two copies on screen; do it every frame and you smear a trail across the display. Clean movement means redraw in the new place and clear the old — and the Amiga's Blitter, with a little help from Blitz, makes that smooth. This unit is about moving blitted graphics without making a mess.

What you'll see by the end

One shape, gliding smoothly around the screen — redrawn every frame, with no trail behind it.

A single ball, moving in a smooth arc. Watch closely: there's exactly one of it at all times, and it leaves nothing behind. That cleanliness is the whole craft of moving graphics — and it's not free; the program is doing real work each frame to make it look effortless.

The whole program

; Blit a shape and move it every frame, drawing flicker-free with two pages.
BLITZ
  ; grab a ball shape from a work bitmap
  BitMap 2,24,24,3
  Circle 12,12,11,6
  Circle 12,12,7,2
  GetaShape 0,0,0,24,24

  ; two display bitmaps for flicker-free motion
  BitMap 0,320,256,3
  BitMap 1,320,256,3
  Slice 0,44,3

  t.f=0
  db=0
  While Joyb(0)=0
    VWait
    Show db
    db=1-db
    Use BitMap db
    Cls 0
    x.w = 148 + Sin(t)*120
    y.w = 112 + Cos(t*1.3)*92
    Blit 0,x,y
    t = t + 0.05
  Wend

After grabbing the ball as a shape (unit 7's trick), the work is the frame loop:

While Joyb(0)=0
  VWait
  Show db
  db=1-db
  Use BitMap db
  Cls 0
  x.w = 148 + Sin(t)*120
  y.w = 112 + Cos(t*1.3)*92
  Blit 0,x,y
  t = t + 0.05
Wend

Each frame: work out a new x,y, clear the page, and Blit 0,x,y stamps the ball there. The position comes from Sin and Cos of a steadily-rising t, which traces the smooth looping path you see. The two new ideas around the blit are how the old ball gets erased and how the redraw stays clean.

Erasing the old position

The simplest way to leave no trail is the one here: clear the whole page and redraw everything. Cls 0 wipes the bitmap black, then Blit puts the ball in its new spot. No old ball survives, because the whole page was cleared. That's exactly what you did in unit 5 for the swarm — clear, redraw, every frame.

It works, but it's heavy-handed: you clear everything to move one thing. Blitz offers a sharper tool — QBlit (queued blit), which remembers where it put a shape and erases just that patch next frame, leaving the rest of the screen untouched. For a mostly-still screen with a few movers, QBlit is far faster than clearing the lot. You don't need it yet — Cls and redraw is perfectly good while you're learning — but know it's there for when a full clear becomes wasteful.

Flicker-free: two pages

The other half of clean motion is double buffering, which you met in unit 5: keep two bitmaps, Show one while you draw the next, then flip (db=1-db, Use BitMap db). The viewer only ever sees a finished frame, so the clear-and-redraw never flickers. Blitting and double-buffering go together: blitting moves the shape, double-buffering hides the seams.

A sharp edge: Blit doesn't clip

One thing that will bite you: a plain Blit doesn't check the edges of the bitmap. Push a shape so it's partly off the side and Blit writes pixels outside the bitmap — which corrupts memory and can lock the machine. That's why this program's Sin/Cos are scaled to keep the ball comfortably inside the bitmap. When a shape genuinely needs to slide off-screen, Blitz has ClipBlit, a slower blit that clips cleanly at the edges. Rule of thumb: keep shapes on the bitmap with plain Blit; reach for ClipBlit when they must cross an edge.

The Blit family

For reference, the blits you'll meet:

  • Blit — stamp a shape. Fast, no clipping, no erase.
  • QBlit — queued blit: stamps and remembers, so it can erase just that patch later. For moving a few things over a kept background.
  • BBlit — like QBlit, but restores whatever was under the shape, not just blank.
  • ClipBlit — a Blit that clips safely at the bitmap edges.

Start with Blit; the others are there as your scenes get busier.

Type it and compile it

Type the program into Ted and press right-Amiga + X (recompile if Blitz asks about memory). The ball glides around its loop. Press fire — or reset — to stop.

Try this: a second ball

Give the ball a partner by blitting the same shape at a second, different position inside the loop:

Blit 0,x,y
Blit 0,300-x,y

Run it — two balls now, mirrored, both clean, both from the one shape and the one Cls. The single clear erases both old positions at once, which is exactly why "clear the whole page" scales so well to many movers.

Try this: change the path

Change t = t + 0.05 to 0.1 for a faster orbit, or change the 120 and 92 (the spread of the Sin/Cos) to make the loop wider or narrower. Keep the numbers small enough that the ball stays on the bitmap — remember, plain Blit won't stop it running off the edge.

What you've learnt

Moving a blitted shape means redraw it in the new place and erase the old. The plain way — Cls the page and redraw — is what you've used; QBlit is the sharper tool that erases only the shape's own patch. Double buffering (two pages, drawn-then-flipped) keeps the motion flicker-free. And the edge to respect: plain Blit doesn't clip, so keep shapes on the bitmap or use ClipBlit. Together, these are how every moving graphic on the Amiga stays clean.

What's next

The ball moves on a path you fixed in code. A game hands that control to the player. Next — Reading the Joystick — you'll throw away the Sin and Cos and steer the shape yourself, the moment a moving picture becomes a game.