Shapes
Boxes and circles are fine, but a game is made of pictures — and you don't want to redraw them line by line every time. A shape is a picture grabbed into memory once, ready to stamp down anywhere, as many times as you like. It's the building block every sprite and tile is made from.
So far you've drawn with Box, Circle and friends — fine for the basics, but a game's graphics are pictures: a ship, a brick, a coin. You don't want to rebuild a picture from scratch every time it appears; you want to draw it once, keep it, and stamp copies wherever you need them. That kept picture is a shape, and stamping it is a blit. Shapes are the raw material of every sprite, every tile, every bullet — and this unit is where your graphics stop being lines and start being things.
What you'll see by the end
Nine identical targets. But the target was only drawn once; the other eight copies are stamps of the same saved shape. Draw once, stamp many — that's the whole idea, and it's how a game fills the screen without redrawing anything.
The whole program
; Draw a picture once, grab it as a shape, then stamp it everywhere.
BLITZ
; draw a target on a small work bitmap, then grab it as shape 0
BitMap 1,32,32,3
For i=1 To 14
Circle 16,16,i,2+i/5
Next
GetaShape 0,0,0,32,32
; the display bitmap
BitMap 0,320,256,3
Cls 0
For n=0 To 8
Blit 0,n*34+8,112
Next
VWait 100
Slice 0,44,3
Show 0
MouseWait
It comes in two halves: make the shape, then stamp it.
Make the shape
BitMap 1,32,32,3
For i=1 To 14
Circle 16,16,i,2+i/5
Next
GetaShape 0,0,0,32,32
First you need a picture to grab. The program makes a small 32×32 work bitmap and draws a target on it — a For loop of growing circles, in a few colours. Then the key line:
GetaShape 0,0,0,32,32lifts a rectangle out of the current bitmap and stores it as shape number 0. The numbers are: the shape number (0), the top-left corner to grab from (0,0), and the size (32,32). After this, shape 0 is your target, held in memory — independent of the bitmap you drew it on.
Stamp it
For n=0 To 8
Blit 0,n*34+8,112
Next
Blit 0,n*34+8,112stamps shape 0 onto the display, at the position you give. Loop it nine times withnspacing the copies across, and you get a row of targets — each one a copy of the same shape, placed in a blink.
Blit is the workhorse you'll use constantly: put this shape, here. Drawing the target took a loop of circles; stamping it takes one Blit.
Why "blit"?
The word comes from the Amiga's Blitter — a piece of custom hardware built for exactly one job: shovelling blocks of graphics around memory at high speed. When you Blit a shape, Blitz hands the work to that chip, which copies the pixels far faster than your program could one at a time. This is the Amiga's secret weapon for moving graphics, and Blitz puts it behind a single keyword. (You'll meet the Blitter properly next unit.)
Type it and compile it
Type the program into Ted and press right-Amiga + X (recompile if Blitz asks about memory). A row of targets appears. Click the mouse to return to the editor.
Try this: a grid of them
Wrap the stamping in a second loop to fill a grid:
For y=0 To 4
For n=0 To 8
Blit 0,n*34+8,y*40+20
Next
Next
Run it — forty-five targets now, all from the one shape, drawn just as fast. That's the power: the cost of making a picture is paid once; every copy after that is a cheap stamp.
Try this: draw your own shape
Change the target into something else. Replace the circle loop with your own drawing on the 32×32 bitmap — a filled box, a couple of lines, a little diamond with Line:
Boxf 4,4,28,28,3
Boxf 10,10,22,22,6
Grab it the same way and stamp it. Whatever you draw in that 32×32 patch becomes the shape — which is exactly how you'll make ships, bricks and coins later.
If it doesn't work
- Nothing appears where you blit. Check the
GetaShapegrabbed the area you drew on — its corner and size must cover your picture. Grab an empty patch and the shape is blank. - The shape is the wrong size or clipped. The
32,32inGetaShapeis the grab size; make it match the picture you drew. - Blitz complains, or the machine locks. Make sure you grab the shape (and
Freethe work bitmap if you wish) before switching to the display bitmap, and that the display bitmap is the current one when youBlit.
What you've learnt
A shape is a picture grabbed into memory once and stamped wherever you need it. GetaShape number,x,y,width,height lifts a rectangle from the current bitmap into a numbered shape; Blit number,x,y stamps that shape onto the display — fast, because it's driven by the Amiga's Blitter chip. Draw once, blit many: that's how a game fills the screen with ships and tiles without redrawing a thing. Shapes are the building block everything that moves is made from.
What's next
You've stamped shapes that stay put. The Blitter that puts them there can also move them — and cleanly erase where they were. Next — Blitting — the difference between stamping a shape and animating one without leaving a trail.