Sprites

From SpecNext official Wiki
Revision as of 00:44, 19 August 2017 by wiki>Hyphz
Jump to: navigation, search

Sprites are 16x16 independently moving images. Each can use up to 256 colors, independently selected from a palette.

To enable sprites, bit 0 of Sprite and Layers System Register ($15) must be set. If bit 1 is set also, sprites are permitted to cross the border.

The Next supports up to 64 sprites on screen at a time. It also supports 64 "patterns" (bitmap images used for sprites). These can be independent - for example, you could have several sprites with the same pattern.

To upload a pattern, write the pattern number to Sprite Status/Slot Select ($303B / 12347). Then write the pattern, byte by byte in reading order, to Sprite Pattern Upload ($xx5B / 91). The pattern must be exactly 256 bytes long, filling the 16x16 available area. Each byte is the index into the palette of the color of that pixel. The default palette simply maps the indexes 0-255 to colors 0-255 which are decoded as in ULAPlus, except that %11100011 (pink) is treated as transparent. Sprites smaller that 16x16 thus must pad the extra space with the transparent color. After 256 bytes are written, continuing to write will write to the next pattern number, and so on.

To display and move sprites, write the sprite number to Sprite Status/Slot Select ($303B / 12347), then control the sprite by writing a 4 byte packet to Sprite Attribute Upload ($xx57 / 87) to which 4 byte packets are set. This sets the position of the sprite, which pattern it displays, and what effects are applied. Full details of the packet contents are given on the page for that port.

You can overwrite the standard palette by sending any value to Sprite Status/Slot Select ($303B / 12347) then sending 256 color values, in ULAPlus format, to ($xx53). Since 256 indices are supported this is not necessary to be able to access every color, but re-ordering the colors will allow the sprite palette offset option at Sprite Attribute Upload ($xx57 / 87) to create effects.

Reading from Sprite Status/Slot Select ($303B / 12347) returns information about the currently available sprites. If bit 1 is set, more than 12 sprites are active on a line, which means that the extra are not being displayed. If bit 0 is set, two or more sprites are overlapping. It is not possible to obtain details of which sprites are overlapping, so this should be used as a signal to run more detailed collision detection.