sprite
sprite copied to clipboard
Execute custom closures during animation
As a prerequisite for sprite-sheet animations, I would like to have some mechanism to invoke my own callbacks as part of a sequence of animation steps. This could be useful to:
- Change the current texture or rectangle in within the texture.
- Trigger higher order events.
- Debug.
This arises a problem: Sprites are parametrized with the texture type. If we want to store a callback function that accepts a sprite as parameter the signature of this type needs to be known by the AnimationState enum. We could pass as well the id of the object, but since it is has been mutable borrowed in the update function, there is no chance to alter the sprite itself as result of the callback.
The options are:
- Parametrize the AnimationState with the Texture type => not very pretty since type can not be deduced as long as the function value is not used.
- Remove the Texture parameter (I) from the Sprite somehow.