Your First Bob
Shapes you draw stay put. A bob is different: a graphic object you place by number, move with a single command, and reposition as often as you like. Make one, drop it on screen, and meet the thing every moving sprite in your game will be built from.
The shapes you drew last unit are painted on — once a Box is down, it's part of the screen, and to move it you'd rub it out and draw it again. That's no way to run a game. What you want is an object you can pick up and put down somewhere else, again and again, smoothly. On the Amiga that object is a bob — short for blitter object, named after the chip that moves it — and it's the workhorse behind almost everything that moves in an AMOS game. This unit makes one and places it; the next makes it move.
What you'll see by the end
A small two-colour block, sitting where you put it. It looks like something you could have drawn with Bar — and you did draw it, once, to make its picture. But what's on screen now is a bob: an object AMOS can move anywhere with a single command, which is what the rest of this phase is about.
The whole program
Hide
Screen Open 0,320,200,16,Lowres
Colour 0,$111
Colour 1,$F40
Colour 2,$FD0
Cls 0
Ink 1
Bar 0,0 To 23,23
Ink 2
Bar 6,6 To 17,17
Get Bob 1,0,0 To 24,24
Cls 0
Bob 1,148,88,1
Wait Vbl
Wait Key
There are three steps here: draw a picture, capture it as a bob image, then place the bob.
Draw the picture
Ink 1
Bar 0,0 To 23,23
Ink 2
Bar 6,6 To 17,17
Nothing new — two filled blocks in the top-left corner, an orange one with a yellow one inside it. This is just an ordinary drawing, made to be the bob's appearance. You're drawing it in the corner because you're about to grab it from there.
Capture it with Get Bob
Get Bob 1,0,0 To 24,24
Get Bob lifts a rectangle of the screen and stores it as a bob image — a picture AMOS keeps in memory, ready to stamp down wherever you ask. The 1 is the image's number; the two corners say which part of the screen to grab (the area you just drew in). After this line, image 1 is your little block, held in memory.
Place it with Bob
Cls 0
Bob 1,148,88,1
First Cls 0 wipes the screen clean — proof the original drawing is gone. Then Bob puts a bob on screen. Its three numbers are: the bob number (which on-screen bob this is — bob 1), the x and y position in pixels (148, 88 — near the centre), and the image number to show (image 1, the one you captured). The block reappears in the middle, even though you cleared the screen — because it's being drawn fresh from the stored image.
Why Wait Vbl
Wait Vbl
Wait Vbl waits for the screen's next refresh — the vertical blank, the brief pause as the Amiga finishes drawing a frame. Moving graphics get placed during that pause so they appear cleanly, without tearing or flicker. You'll meet it properly in the frame loop next unit; for now, it makes the bob settle neatly.
Image versus object
The idea to hold onto is the split between the image and the bob. The image (number 1, made by Get Bob) is the picture — drawn once, stored, never moved. The bob (also numbered, placed by Bob) is the thing on screen that shows that picture at a position. One image can be shown by many bobs, and a bob can be moved without touching its image. That separation — a picture made once, displayed and moved cheaply — is exactly what makes a bob fast enough to fly around a game.
Type it and run it
Type the program in and press F1. The bob appears in the centre. Press a key to return to the editor.
Try this: place it somewhere else
Change Bob 1,148,88,1 to Bob 1,40,30,1 and run it. The same bob, the same image, a different spot — moving it is just different numbers. That's the whole promise: change the position, and the object follows.
Try this: two bobs, one image
Add a second line before Wait Vbl:
Bob 2,220,140,1
Run it, and a second block appears — bob number 2, showing the same image 1. One picture, two objects on screen. That's how a game fills the screen with copies of a thing without drawing each one by hand.
If it doesn't work
- Nothing appears after the
Cls. Check theGet Bobgrabbed the right area — its corners must cover where you drew. Grab an empty patch and the bob image is blank. - The bob is in the wrong place. The two middle numbers in
Bobare x then y, in pixels from the top-left. Bigger y is lower down. - AMOS complains about
Get BoborBob. Check the comma-separated numbers are all there:Get Bobneeds an image number and two corners;Bobneeds a bob number, x, y, and an image number.
What you've learnt
A bob is a graphic object you place and move by number, not paint by hand. You draw a picture, capture it with Get Bob image,x1,y1 To x2,y2, then place it with Bob number,x,y,image. The image is the stored picture; the bob is the movable object showing it — and keeping them separate is what lets one picture become many fast-moving objects. Wait Vbl settles the drawing to the screen's refresh.
What's next
Your bob sits still because you placed it once. Next — The Frame Loop — you'll place it over and over inside a loop, nudging its position a little each time, and watch it move. That loop is the heartbeat every game runs on.