Your Spectrum
YS MegaBasic manual - Sprite Designer
Home YS MegaBasic Contents

SPRITE DESIGNER

MEGASPECTRUM SPRITES

Sprites are graphic shapes that can be made to move around the screen. Their shape, colour, direction and speed can be defined by the user, and each sprite can have more than one image associated with it. As the sprite moves along it can be made to change shape by switching its image - in this way sprites can be animated. On the MegaSpectrum you can make use of eight sprites, numbered from zero to seven.
  The 'SPRON_' command is used to activate the sprites. It's followed by two numeric expressions - the first showing which sprite is to be activated and the second, how the sprite should be plotted on the screen (a result of one causes it to be ORed onto the screen, two will XOR it). 'SPROFF_' deactivates the sprites and is followed by a single numeric expression - the number of the sprite to be deactivated.
  Sprites on the MegaSpectrum are made up on a 16 by 16 pixel square, and each group of eight by eight pixels can have its own attribute. Two separate areas of memory are used to define sprites. The first, from address 56750 to 56893, contains all information associated with a sprite, except for its shape. Eighteen bytes are used for each sprite so the information for sprite zero starts at address 56750 and the information for sprite one starts at address 56768, and so on. The start of a particular sprite's information is given by:

  s=56750+18*n

Where 's' is the start of the information and 'n' is the number of the sprite required.
  The 'mode' of the sprite is defined by's+0'. Depending on the value of 's' the sprite is ORed onto the screen (s=1), the sprite is XORed onto the screen (s=2) or the sprite is inactive (s=0) - that is, it's not plotted onto the screen. The end of the sprite information area is signalled by a byte of 255; a good way to turn all sprites off at once is to execute the command 'POKE 56750,255'.
  Sprites use the same co-ordinate system as 'SPUT_' and 'SPRINT_'. Thus:
s+1 x co-ordinate of sprite (0-255).
s+2 y co-ordinate of sprite (0-175).
s+3 x increment.
s+4 y increment.
s+5 Time taken to move the sprite.
s+7 Number of images.
s+9 Time between the change of images.
s+11/s+12 Address of the first image.
s+15 Attribute used for erasing the sprite.
21

The second area used for the image information for all sprites is between RAMTOP and address 44999, and is variable in length. A total of 36 bytes are used for each image; the first 32 bytes define the shape of the image and the last four contain the image's attributes.
  As mentioned earlier, 's+11' and 's+12' show the address of the first image of each sprite. If a sprite has more than one image associated with it then it must follow the image that's pointed to by 's+11'and 's+12'. Each sprite does not have to have its own image information. If there are a number of sprites of the same shape then there only has to be one image; all that's needed is for the values 's+11' and 's+12' (for each sprite) to point to the same image.

SPRITE DESIGNER - THE PROGRAM

The Sprite Designer program follows YS MegaBasic on tape and is loaded by:

  LOAD "SPD"

It will run automatically, and enable sprites to be defined easily and stored away on tape or Microdrive ready for exploitation in your own programs. The screen layout is as follows. The cyan square to the left is the area of the screen used to design images, and the area to the right is where most information is displayed. The bottom area of the screen is where user input appears.
  Once it's loaded, there are a number of options to choose from:
Create a sprite Allows the user to define the co-ordinates, direction and speed of a sprite.
View a series of images Provides the option to view an image on-screen at its normal size. This facility is only available if there are already some images in memory.
Create an image Clears 36 bytes at RAMTOP to accommodate another image.
Edit an image Allows an image to be drawn on-screen.
Save images and sprites Saves the current sprite and image information to tape or Microdrive.
Load images and sprites Allows the set of sprites and images to be loaded into memory.
Copy to Microdrive Enables Sprite Designer to be transferred to Microdrive.
Return to Basic Returns the user to YS MegaBasic.To re-start the Sprite Designer, type 'GO TO 5' and press Enter. Remember that although images are numbered from zero upwards, the first image (number zero) is highest in memory.
22

You're asked to provide a file name up to eight characters in length. Three files are saved - if, say, 'Winston' was the filename, then the saved files would be called 'Winston.n', 'Winston.i' and 'Winston.s'. 'Winston.n' is a one-byte file indicating the number of images saved, 'Winston.i' holds the image data and 'Winston.s' provides the sprite information.
  To load a set of images and sprites into your own program, you could use the following sequence:

  9000 LOAD N$+".n" CODE 23296
  9010 CLEAR 44999-36*PEEK 23296
  9020 LOAD N$+".i" CODE
  9030 LOAD N$+".s" CODE
23