of our screen and make it visible. Let's add the appropriate commands now to our program:
100 SPRITE PRINT 1
130 SPRITE 0,152,119,0,1
to make sure that our sprite will stay on screen (as the NextBASIC editor will make it invisible temporarily when invoked), we should add one more line:
150 PAUSE 0
which will ensure the computer is waiting on our keypress before returning to NextBASIC. Now RUN the program.
Presto! Our Spaceship is sitting idle, doing nothing, in the middle of our screen. But wait a second? 152 and 119 don't look anywhere like the middle of the screen. We know our resolution in Layer 0 can be expressed in values between 0 and 255 for x and 0 and 191 for y correct? Well wrong! It's time now to refer back to Chapter 15 and also examine Fig. 13 one more time where we will see that the Sprite System has a resolution of 320 w x 256 h pixels.
This gives us 32 more pixels on every side than our standard resolution Layer 0 and Layer 2 screens. Now placement of the sprite begins with the upper left corner and a sprite is 16 x 16 so in order to be placed at the centre of the screen you divide the horizontal and vertical in half and then subtract a further 8 pixels to center the sprite. Normally the border hides the sprites so setting an x,y set of 0,0 would leave the sprite invisible. There is something we can do about that however and that's use:
which sets the sprites to print over the border if n is set to 1 or under it if n is set to 0. Let's try it by adding the command and changing line 140 to show the sprite at that coordinate with:
105 SPRITE BORDER 1
130 SPRITE 0,0,0,0,1
To execute with the latest changes, do not RUN the program again, as this will repeat the process and commit one more bank to the sprite DATA we entered originally. Instead type GO TO 100. You may even want to test this without line 105 to see the difference. One more command related to the above is:
which sets the clip window for sprites from (x1,y1) to (x2,y2). Any part of a sprite outside this window is not visible. Note that this has no effect if sprites over the border (SPRITE BORDER 1) is enabled.
This chapter however is called Time and Motion and with sprites so far we haven't seen motion at all! Well, let's change that; as we spoke in the introduction a sprite can be animated by moving it about the screen or by changing its bitmap to something different and most of the time, both at the same time. In order however to animate the bitmap of a sprite, a new pattern has to be defined. Let's do that by adding a few lines to our program and modifying some existing ones. First remove lines 140 and 150, then modify these:
50 FOR F=0 TO 511
80 SAVE "spaceship.spr" BANK a,0,512
and then add these:
106 FOR %a= 1 TO 50
139 %s=1-s
ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.