EasyManua.ls Logo

Commodore Amiga A2000 - Moving a Sprite

Commodore Amiga A2000
380 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
MOVING A SPRITE
A sprite generated in automatic mode can be moved by specifying a different position in
the data structure. For each display field, the data is reread and the sprite redrawn.
Therefore, if you change the position data before the sprite is redrawn, it will appear in a
new position and will seem to be moving.
You must take care that you are not moving the sprite (that is, changing control word
data) at the same time that the system is using that data to find out where to display the
object. If you do so, the system might find the start position for one field and the stop
position for the following field as it retrieves data for display. This would cause a "glitch"
and would mess up the screen. Therefore, you should change the content of the control
words only during a time when the system is not trying to read them. Usually, the vertical
blanking period is a safe time, so moving the sprites becomes part of the vertical blanking
tasks and is handled by the Copper as shown in the example below.
As sprites move about on the screen, they can collide with each other or with either of the
two playfields. You can use the hardware to detect these collisions and exploit this
capability for special effects. In addition, you can use collision detection to keep a moving
object within specified on-screen boundaries. Collision Detection is described in Chapter 7,
"System Control Hardware."
In this example of moving a sprite, the spaceship is bounced around on the screen,
changing direction whenever it reaches an edge.
The sprite position data, containing VSTART and HSTART, lives in memory at $25000.
VSTOP is located at $25002. You write to these locations to move the sprite. Once during
each frame, VSTART is incremented (or decremented) by 1 and HSTART by 2. Then a new
VSTOP is calculated, which will be the new VSTART+6.
MOVE.B #151,d0 ; Initialize horizontal count
MOVE.B #194,d1 ; Initialize vertical count
MOVE.B #64,d2 ; Initialize horizontal position
MOVE.B #44,d3 ; Initialize vertical position
MOVE.B #1,d4 ; Initialize horizontal increment value
MOVE.B #1,d5 ; Initialize vertical increment value
;
; Here we wait for the start of the screen updating.
; This ensures a glitch-free display.
;
LEA CUSTOM,a0 ; Set custom chip base pointer
VLOOP:
MOVE.B VHPOSR(a0),d6 ; Read Vertical beam position.
; Only insert the following line if you are using a PAL machine.
; CMP.B #$20,d6 ; Compare with end of PAL screen.
BNE.S VLOOP ; Loop if not end of screen.
; Alternatively you can use the following code:
; VLOOP:
- 110 Sprite Hardware -

Table of Contents

Other manuals for Commodore Amiga A2000

Related product manuals