remy / zx-tools

A collection of ZX web based tools and libraries
https://zx.remysharp.com
41 stars 3 forks source link

Add support for relative sprites in the animation tool #38

Open paulossilva opened 4 years ago

paulossilva commented 4 years ago

The sprite engine provided with the Next machine features relatives sprites, which allows us to use more than one sprite to compound a bigger or layered one. Relative sprites can be one of two types: Composite ou Unified.

Composite sprites can have some of their attributes relatively set to their anchor sprite, namely: x and y coordinates, visibility, pattern number and palette offset, whereas Unified sprites inherent some of their anchor's attributes, like scale, rotation and mirroring.

Extending the sprite tool to support the creation/animation of relative sprites would be great for a number of reasons.

A few requirements I can think of now:

  1. For the whole animation define an anchor sprite and optionally set its relative sprites (all must be of the same type)
  2. For each relative sprite/frame, define its relative parameters (x and y coordinates, pattern, palette offset, scale, rotation and mirroring). If an attribute is not set in a frame, it means it doesn't change in that frame from the previous one.

This feature, atop of the previous issue, would greatly improve the sprite tooling.

With these features we could compose and animate an energy bar using the provided sprite sheet. Even further, we could change the colour of the energy bar when it reaches a low level by changing its palette colour index/offset.

paulossilva commented 4 years ago

Being more specific on how to add the relative sprite's attributes and suggesting an UI to handle them (apply to both composite and unified sprites):

  1. Visibility would be just a checkbox to set whether a relative sprite is visible or not. Making an anchor sprite not visible makes all relative sprites invisible too regardless their visibility attribute (which has no practical effect on the animation tool).

  2. X,Y coordinates are relative offsets (-127 to 127) from the coordinates of the anchor. UI could use a spinner input field.

  3. Pattern number could be relative to the anchor or independent from it (so is the palette offset), depending on whether specific attribute bits are set or not. Considering the sprite animation tool is aimed to help to build animations but not to generate code for it, the UI could be simplified to use input fields for entering independent values from their anchor sprite. An extra mile target would be let the user select a checkbox to determine whether these values are relative or absolute.

For Composite sprites, the following attributes are all independent from the anchor sprite:

  1. Rotation, X-mirroring and Y-mirroring are just flags and could use of a traditional checkbox.
  2. X-scaling and Y-scaling factors should be one of the values 1x, 2x, 4x and 8x.

For Unified sprites, these attributes are controlled by the anchor sprite, so they can't be changed individually on each relative sprite. Thus, the UI could just disable these fields.