Skip to content

Allow sprites to be renumbered #319

@stevesims

Description

@stevesims

Sprites are always drawn in numerical order, low to high, so higher number sprites always get drawn on top of lower numbered sprites. The nature of how hardware sprites work is that they will all always be above software sprites.

There is no mechanism provided to renumber sprites, or to shuffle their order.

Currently if a program wishes to adjust the drawing order of sprites, they need to redefine the sprites affected. As sprites with no frames defined or those marked as hidden, users can make gaps in their sprite lists, which can help with this.

To better aid programs adjust the drawing order of sprites we could consider adding APIs to help with sprite renumbering.

The sprites list in agon-vdp is currently a plain C array of Sprites objects. To aid shuffling of sprites, this could be an array of pointers instead.

Possible APIs to add would be ones to "swap" two sprites, "delete" a sprite from the list, and "insert" a sprite into the list. Inserting or deleting would effectively renumber sprites. Deleting a sprite would need to move all sprites after that one down a slot and insert a new sprite at the end of the list. Inserting a sprite would need to move all sprites from the selected slot up one, deleting the last in the list, and inserting a new sprite at the selection spot.

A question that would need to be thought about here is whether inserting or deleting a sprite should affect the number of active sprites. For efficiency, a case to be made to leave the number of active sprites the same, however deleting a visible software sprite would need the sprites to be hidden to ensure that they get properly erased. Inserting a sprite may also push a software sprite outside of the active range too, so if the final sprite in the list is a software sprite that would also need to get erased.

Swapping sprites would have similar problems, as if a visible software sprite is swapped to be outside of the range of active sprites that would also need to be hidden.

Changing the number of active sprites always forces all sprites to be hidden before the number of active sprites changes which, when software sprites are being used, is a fairly costly operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions