Unity


Sprite destruction

Dynamic system for sprite destruction in Unity. It uses a mask or custom function to dynamically destroy sprites while conserving their position and speed. The Burst compiler and Jobs system are used in most steps of the process.

  • The sprite image is updated, applying the mask or function for changing the color of pixels, or destroying them (turning them fully transparent).
  • The resulting image is then checked for different sprite islands using a custom algorithm. It caches results from each island discovered, in order to avoid duplicate work while discovering more islands.
  • While generating the islands, their borders are also stored.
  • A flood fill algorithm (quickfill) is used to copy each island to a different sprite image.
  • The border of each island is preprocessed and then simplified, so that resulting colliders are not overly complex.
  • Gameobjects, sprites, and rigidbodies are set up for each new sprite island.

The demo also has the skeleton of a simple custom sprite animation system (using programmer art).