Sonic the hedgehog 2

The sprites programming topic

By Sonic Hachelle-Bee on May 21 2005.
In this topic, I will put informations about how to create a new sprite from scratch in hex and ASM. This requires some programmation skills to understand fully how things works.

For now, here is just how a sprite is defined:

Actually, a sprite definition looks like a C++ class. This one is based on the one of the Dinobot (HPZ), but usually, this works the same for the other sprites:

General format:
Private variables:
Here is a lot of private variables for each sprite. These variables contains informations about the sprite current status: object type, position, display plane, collision, internal counters... These variables are all in the sprites status table in RAM.

Begin
Registers initialisations
Set object number routine counter and read offset index

Constructor:
Set pointer to mapping
Set VRAM position and pallet
Set sprite display plane
Set action area width
Set action spot
Set collision/hurt type
Start movement subroutine
Gravity and edges detection subroutine
Jump to Render

Render:
Set object subparameter routine counter and read offset index
Jump to Subparameters definitions and movements
Set pointer to frames speed
Frames rendering subroutine
Inside viewport test:
If yes: Plane rendering subroutine and read patterns
If not: Internal destructor

Subparameters definitions and movements:
For each subparameter linked by the offset index:
Sprite subparameter definition and conditions
Sprite subparameter movement calculations
Movement control subroutine
Gravity and edges detection subroutine
Set another subparameter for the next time if necessary

Destructor:
Clear memory location subroutine

End

Usually, after the sprite definition, you have the frames speed and mapping of the sprite. Pointers to all subroutines are at the end, after the mapping.


Back to: Sonic the hedgehog 2
Table of contents