<!-- PDF page 139 -->

This would be done to animate the relative sprites separately, so that one relative sprite might animate whilst the others remain the same (for example). However, it can also be used to automatically move a relative sprite around within a composite/group sprite. The main restriction here is that the movement limits are unsigned, so this works best for relative sprites with positive offsets (add **256** to negative offsets when specifiying them in a movement range).

Automatic movement can be temporarily suspended for particular (or all) sprites if so desired by using:

#### SPRITE PAUSE *s1* [TO *s2*]

which turns off automatic movement for a single sprite *s1* or a range (*s1 – s2*) of sprites. Said suspension is lifted by using:

#### SPRITE CONTINUE *s1* [TO s2]

which restarts automatic movement for a single or a range of sprites as above.

### Sprite functions

In order to return details about sprites, and to make collision detection checks, several functions are provided[^p139-4]. These are:

#### SPRITE *s*

which shows if sprite *s* is visible. Returns **1** (true) if sprite is visible or **0** (false) if not.

#### SPRITE CONTINUE s

Returns a bitmask describing the automatic movement enabled for sprite *s*:

bit **0**: set if automatic movement is enabled

bit **1**: set if currently moving in the *Y axis*

bit **2**: set if currently moving in the *X axis*

Note that if bit **0** is set but neither bits **1**or **2** are set, that means that only the pattern is being animated.

#### SPRITE AT(*s,c*)

Returns a coordinate or other movement-related value for the sprite:

| | |
|---|---|
| **SPRITE AT**(*s*,**0**) | returns *x coordinate* |
| **SPRITE AT**(*s*,**1**) | returns *y coordinate* |
| **SPRITE AT**(*s*,**2**) | returns *pattern number* |
| **SPRITE AT**(*s*,**3**) | returns *x step* |
| **SPRITE AT**(*s*,**4**) | returns *y step* |
| **SPRITE AT**(*s*,**5**) | returns *delay* before the sprite next moves[^p139-5] |

One of the most labour-intensive game programming tasks is trying to figure out when two sprites have collided. NextBASIC provides that information with

#### SPRITE OVER(*s1, s2* [TO *s3*] [,*overlapX* [,*overlapY*] ])

which performs a bounding-box collision detection between sprite *s1*, and a single other sprite *s2* or a range of sprites *s2...s3*.

Two optional acceptable overlaps (in pixels) can be provided in *overlapX* and *overlapY*. If *overlapX* is not present, **0** (no overlap) is used. If *overlapY* is not present, then the value of *overlapX* is used. Overlaps should be **0...7** for an unscaled sprite *s1*, or **0...15** for a 2x scaled sprite etc. Overlaps allow for some flexibility before declaring a collision especially since sprite patterns do not always extend to the boundaries of the sprite bounding box (16 x 16)

[^p139-4]: All these functions are available in the standard expression evaluator and the integer expression evaluator
[^p139-5]: A returned value of **0** means the sprite will move on the next **SPRITE MOVE** command.

