Animation - PixolotlDev/MarioClone GitHub Wiki

Overview

As a consequence of how spritesheets work in this implementation, animation is exceptionally easy to represent. An animation file in this framework consists of initial information, such as the default frame rate and other relevant information, followed by the "indexes" of the sprites used in the animation. For example, the player's run animation at 10fps could be represented as:
10 128 |16 0 16 16| |32 0 16 16| |48 0 16 16|
or, in binary:
00001010 10000000 |00010000 00000000 00010000 00010000|00100000 00000000 00010000 00010000|00110000 00000000 00010000 00010000|01000000 00000000 00010000 00010000

In the program itself, these values are baked into the code, entirely due to time constraints and over-scoping. In a finished version, animations would be loaded from files instead.

Palette Animations

Sometimes, the game requires palettes to be switched in quick succession. For this, a different kind of animation is required, as this effect will often happen on top of other sprite animations, such as the player having the invincibility powerup while running.

Mario running with invincibility

These animations are even simpler to represent than sprite animations - all it needs is a framerate, followed by the indexes of this sprite's respective palette. For example, the animation file for the invincibility shown above, at 5fps, would look like:
5 0 4 5 6 (0 represents the initial colour of the sprite, which might change depending on the player's state, such as being player 2 or having fire power)
or, in binary:
00000101 00000000 00000100 00000101 00000110

Initial Values

As discussed before, a sprite animation will begin with some initial values before the sprite data is described. Those values are as follows:

  • Framerate (uint8): the number of frames of the animation that the program will progress through in one second
    • If this is 0 and loops, this usually means the program is meant to alter the framerate somehow, like with running speed
  • Flags (byte):
    • Loop: whether or not the animation loops or ends on the final frame
    • MustFinish: animation must complete before another can begin
    • Unused bit
    • Unused bit
    • Unused bit
    • Unused bit
    • Unused bit
    • Unused bit