Updating Objects

This Chapter explains the theory behind the AMOS Professional system for updating and drawing moving objects. As well as a comprehensive range of commands, a completely automatic system is provided for your use.

Moving multiple objects

As a default condition, AMOS Professional manages the position of each and every object on the screen automatically. The moment that the coordinates of these objects change, they are re- drawn almost instantly. When it comes to programming complex arcade games, that "almost instantly" can cause problems!

The next two ready-made programs demonstrate a typical problem, first with Sprites and then with Bobs. If you examine them, you will see that the objects are moving at slightly irregular times, because even though AMOS Professional is updating their positions at regular intervals, it is not keeping pace with the FOR ... NEXT loop.

To avoid wobbly Sprites and Bobs, all objects must be re-drawn at the same instant in your program, and AMOS Professional provides three commands for this purpose. SPRITE UPDATE, is to be used for updating Sprites, BOB UPDATE displays Blitter Objects and the UPDATE command re-draws both Sprites and Bobs in the same operation.

Before calling any of these commands, the automatic updating system must be disengaged using the relevant command, SPRITE UPDATE OFF, BOB UPDATE OFF or UPDATE OFF, as appropriate. Here are two working examples to type in yourself:

Load "AMOSPro_Tutorial:Objects/Sprites.Abk" Curs Off : Flash Off : Cls 0 Set Sprite Buffer 256 Hide On Get Sprite Palette Sprite Update Off For X=X Hard(0) To X Hard(330) For S=0 To 8 Sprite S+8,X,S*25+50,2 Next S Sprite Update : Wait Vbl Next X
Load "AMOSPro Tutorial:Objects/Bobs.Abk" Curs Off : Flash Off : Cls 0 Double Buffer Get Bob Palette Bob Update Off For X=0 To 330 For B=0 To 1 Bob B,X,B*90,2 Next B Bob Update Wait Vbl Next X

Displaying objects over a changing background

When objects need to be displayed against a rapidly changing background picture, other problems can occur. The most important thing to understand is that although they can hold the same images, Sprites and Bobs are completely different from one another. The following tables set out these differences.



This has far reaching implications for your programming, and is the crucial reason for the entire DOUBLE BUFFER system. It is the complete independence of Sprites that make them so useful.

AMOS Professional allows you to use Bobs with animated screens, and the next section explains how screens are updated to permit this.

The update process

This explanation of the Bob movement system is very detailed. If you are not interested in the theory, then the BOB CLEAR and BOB DRAW commands are explained later in this Chapter, and will be enough to allow you to proceed.

The updating of single buffered screens will now be examined. Supposing you want to display a single Witter Object on the screen. The following steps need to be undertaken:

If you are using double buffered screens, a separate copy of the background area is created for each of the two screens. At the end of a display routine, the logical and physical screens are swapped around by the system, to ensure that these two screens are perfectly synchronised. All the time that the contents of an animated screen stay completely still, there can be no problems with updating a static image. Unfortunately, as soon as the contents of a screen changes, the saved sections of the previous picture will be copied straight onto the updated screen, and corrupt the picture. This can only be solved if all of the standard drawing commands are synchronised with both the physical and logical screens, and AMOS Professional achieves this by means of the powerful AUTOBACK system.

AUTOBACK is extremely intelligent and completely automatic, but it can only synchronise graphics and text commands. If you wish to manipulate the screen directly with SCREEN COPY or SCROLL, you must handle the process yourself. In other words, you will have to keep the logical and physical screens in step with one another and perform exactly the same operations in both screens.

This routine demonstrates the danger of flicking between these screens when different items are held in the two components of double buffering:

Double Buffer Autoback 0 Do Paper 4 : Print "Hello from the first screen" Screen Swap : Wait Vbl Paper 6 : Print "Greetings from screen two" Screen Swap : Wait Vbl Loop

The updating commands

Under normal circumstances, AMOS Professional displays all Bobs at once. So if any Bob coordinates are changed, that Bob can be expected to appear at its new position immediately.

Unfortunately, the Amiga's hardware is only capable of re-drawing a limited number of objects on screen in any single display cycle. This means that if you try and move several Bobs at once, it is almost inevitable that some of those objects will be re-positioned at slightly different times. This phenomenon generates unpleasant jerky movements. Thankfully, AMOS Professional provides a simple solution to this problem.


instruction: move many Bobs simultaneously
Bob Update
Bob Update Off
Bob Update On

BOB UPDATE performs all Bob movements in a single, mighty burst, so all objects are moved at the same instant in your program. The resulting movement effects are now incredibly smooth, even with dozens of objects on screen at once. BOB UPDATE is extremely easy to use, as the following technique explains.

BOB UPDATE is now used as the standard technique in the vast majority of AMOS arcade games.

If you need to restore the re-drawing system to its default status, BOB UPDATE ON sets the situation back to normal. One word of warning though, if you are already swapping the screens manually with SCREEN SWAP, use BOB UPDATE carefully, because it will switch between the logical and physical screens immediately after your Bobs have been updated. The simplest remedy for any problems this may cause is to use BOB CLEAR and BOB DRAW instead. These are explained later.


instruction: move all Sprites at once
Sprite Update
Sprite Update Off
Sprite Update On

You may want to remind yourself of this family of commands, which are explained in Chapter 7.1. They parallel the BOB UPDATE commands, and are used in the same way.

You are recommended to add a WAIT VBL instruction after each SPRITE UPDATE, to make sure that Sprite movements are perfectly synchronised with the existing screen display.


instruction: move all objects at once
Update Off
Update On

The UPDATE commands are a combination of the BOB UPDATE and SPRITE UPDATE families, and they are used to re-draw all objects on the screen in a single operation. UPDATE OFF turns off the automatic re-drawing system, so that any Bob or Sprite commands will appear to be completely ignored. In actual fact, they are still going on invisibly, in the background.

UPDATE displays any objects which have moved since the last update. You are recommended to add a WAIT VBL instruction to ensure a smooth effect.

UPDATE ON returns the updating system back to the original automatic setting.


instruction: clear all Bobs from the screen
Bob Clear


instruction: re-draw all Bobs on screen
Bob Draw

This pair of commands is used to synchronise Bob updates with complex screen movements, and generate superbly smooth scrolling screen effects. The technique is achieved by the following steps.

Note that BOB CLEAR and BOB DRAW will only work on the current logical screen, so if DOUBLE BUFFER has been activated, a SCREEN SWAP command will be needed to call the relevant display, as follows:

Screen Swap : Wait Vbl

Also remember to turn off the automatic updating system completely before use. Here is the correct procedure.

Autoback 0

If you are using double buffering, you must make sure that there is a genuine connection between the logical and physical screens. To achieve smooth graphics, there must be a sensible progression from screen to screen, otherwise flickering distortions will be displayed.

When scrolling the playing area of a computer game, it is often possible to ensure that screens are already in step, so BOB CLEAR and BOB DRAW can be used without any problems. In other situations, you may need to make radical changes from screen to screen, so ensure that these are made both copies of the current screen.

The Autoback command

The standard Bob routines only work if the logical and physical screens are in perfect harmony. The instant that text or graphics are drawn, or the SCREEN COPY command is used, the two screens fall out of step with one another, ruining any smooth effects. In the case of SCREEN COPY, you must take control over the system with the BOB DRAW and BOB CLEAR commands, but when using standard graphics commands, the situation is much easier.

AMOS Professional includes a powerful feature that automatically synchronises all text and graphics operations with all Bob updates. This means that once DOUBLE BUFFER is activated, graphics and text can be displayed as normal. This is the principle of the AUTOBACK system.


instruction: set mode for graphics operations on double buffered screen
Autoback mode

There are three AUTOBACK modes, and you can toggle between them by setting the mode values as follows:

Autoback 0

Manual mode. This mode deactivates the AUTOBACK system completely, so that graphics are drawn directly on the logical screen, for maximum speed. It is recommended for use with the BOB DRAW and BOB CLEAR commands.

AUTOBACK 0 is useful when large amounts of graphics are drawn on screens being switched manually with SCREEN SWAP, because it is much faster than the standard system. But remember that you must take responsibility for synchronising between the logical and physical screens.

Autoback 1

Semi-automatic. In mode 1, AUTOBACK performs all graphical operations on both the logical and physical screens. Although Bob updates are not taken into account, this is an ideal mode for displaying hi-score tables and control panels. So as long as your Bobs are kept clear of any new graphics, this mode is perfect.

Autoback 2

Fully-automatic. This setting re-activates the normal AUTOBACK system. Under mode 2, whenever graphics are drawn on screen, they will be synchronised with any active Bobs automatically. All worries are taken care of by the system.

Bob drawing modes

Once Bobs have been set up, you are allowed to change the way that they react with other screen graphics.


instruction: set drawing mode for Bobs
Set Bob number,background,planes,mask

SET BOB is used to change the drawing mode used to display a particular Blitter Object. It is best used before displaying a Bob on the screen. This command has several parameters, of which the first is simply the number of the Bob to be affected.

The second parameter is a number that sets the mode of the background, in other words, the way that graphics underneath the Bob are to be re-drawn. There are three alternative background mode settings. A value of zero automatically replaces the screen background beneath the Bob, after it moves away. This is the standard drawing system, and gives a smooth animation effect when the Bob is moved across the screen.

If the background is a positive number, then the original background graphics are completely forgotten when the Bob moves away, and the area beneath the Bob is replaced by a solid block of colour. The colour is calculated with this formula:

Colour = Background-1

So the following line sets the mode of Bob 1, and draws a block of graphics in colour 9 (calculated as 10-1) whenever the Bob is moved. Notice how commas must be included if other parameter values are omitted. Set Bob 1,10,,

Since this operation is much faster than the standard system, it is recommended for bursts of extra speed. It can be used for moving Bobs across areas such as clear blue sky, and is also extremely effective when operated with the various rainbow effects.

The final alternative background setting is to use a negative value. This turns off the re-drawing process, allowing you to fill the old background areas with any colours or patterns you like, using the standard AMOS Professional graphics commands.

After the two parameters that set the Bob number, and the background mode, SET BOB requires a parameter to establish which of the screen planes is to be used for the Bob. The planes setting is a bit-map, consisting of a binary number where each digit represents one plane of the screen, and each plane represents one bit of the final colour to be displayed on screen. The numbering system works like this:

Plane: 543210 Digit: %111111

By changing these planes, selected colours can be omitted from the Bob when it is drawn on screen. For example:

Set Bob 1,0,$000111 : Rem Display bits drawn in colours 0 to 7 Set Bob 1,0,$111111 : Rem Display all bit-planes

The last SET BOB parameter is another bit pattern, that selects one of 255 possible Miler modes used to draw Bobs on screen. This can set a mask, so that colour zero is transparent, and a full description of the available modes is given at the beginning of Chapter 6.2, in the SCREEN COPY section. In fact, the mask parameter is usually set to one of two values:

%11100010 if no mask is to be used.

%11001010 if the Bob is to be used with a mask, in other words, if colour zero is to be transparent.

So the following line would set Bob 1 moving across the original screen colours, with a mask set:

Set Bob 1,0,%111111, %11001010

Advanced users may find the following information useful:

Blitter SourcePurpose
ABlitter Mask
BBlitter Object
CDestination Screen