https://github.com/rephidock/rephidock.atomicanimations
Classes for simple animations that accept delegates
https://github.com/rephidock/rephidock.atomicanimations
animation easing tween
Last synced: 9 months ago
JSON representation
Classes for simple animations that accept delegates
- Host: GitHub
- URL: https://github.com/rephidock/rephidock.atomicanimations
- Owner: Rephidock
- License: mit
- Created: 2024-02-25T15:07:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T21:02:05.000Z (over 1 year ago)
- Last Synced: 2024-05-22T15:39:40.634Z (over 1 year ago)
- Topics: animation, easing, tween
- Language: C#
- Homepage:
- Size: 247 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rephidock.AtomicAnimations
[](https://github.com/Rephidock/Rephidock.AtomicAnimations/blob/main/LICENSE) [](https://www.nuget.org/packages/Rephidock.AtomicAnimations)
Basic callback-based user-controlled animations and coroutines written in vanilla C#.
## Quick summary
The package provides:
- Animation 'atoms', which mutate `float` values via addition or overwriting using callbacks.
- `AnimationRunner` and `AnimationQueue` to run given animations.
- Waves for animations that can be interpreted as moving waves (curves).
- Coroutines – animations based on `IEnumerable`, allowing for state and logic.
This package does *not* create additional clocks or threads to be transparent about control flow. Use the `Update(TimeSpan deltaTime)` to provide time flow to animations, runners and queues.
Additionally queues and coroutines account for excess time since each atom finishes for better accuracy when chaining animations together.
## Contents
The package provides the following animations out of the box:
| Animation | Summary |
| -------------------------------- | ----------------------------------------------------------- |
| `Shift1D`, 2D, 3D, 4D | Changes 1 to 4 values by adding differences between updates |
| `Move1D`, 2D, 3D, 4D | Changes 1 to 4 values by setting values directly |
| `.Waves.WaveEase` | Calls an update delegate with a moving Wave (curve) |
| `.Coroutines.CoroutineAnimation` | Structures others animations, timing, state and logic |
To control the easing of values use the static methods in the `Easing` class. All easing functions are normalized.
`EasingCurve` delegate is included.
Use a queue or a runner to execute multiple animations.
Animations can be added to both during their runtime (fire-and-forget).
| Runner | Summary |
| ----------------- | ------------------------------------------------------------------------ |
| `AnimationRunner` | Runs animations in parallel. Starts animations the moment they are added |
| `AnimationQueue` | Runs animations in series. Supports `Lazy` |
For creating animations from scratch you can use the following classes in the `.Base` namespace:
| Abstract Class | Summary |
| ---------------- | ------------------------------------------------------- |
| `Animation` | Base class for all animations |
| `TimedAnimation` | `Animation` with a known Duration |
| `Ease` | `TimedAnimation` with defined easing and progress value |
### `.Waves` namespace
The `.Waves` namespaces allows for animations that can be interpreted as a moving wave.
Use the `WaveBuilder` to scale and join multiple `EasingCurve`s together, forming a more complex `Wave`. The waves do not have to start and end at the same value and extend infinitely out of bounds as flat lines.
The `WaveEase.CreateRunthrough` will create an animation atom that moves a given wave through a span of known width calling a delegate with a `ShiftedWave` each update.
### `.Coroutines` namespace
The `CoroutineAnimation` allows for building more complex animations. It is based on `IEnumerable`, which can hold state and logic if made using a custom iterator/generator.
A single `CoroutineYield` holds either
- an animation that is to play the moment it is returned or
- a separate delay instruction
The following delays are possible:
- (static) `CoroutineYield.WaitPrevious`: Waiting for the previous animation to finish
- (static) `CoroutineYield.Join`: Waiting for all previous animations to finish
- (static) `CoroutineYield.Sleep`: Waiting for a delay of specified time
- `CoroutineYield.WaitUntil`: Waiting until a timestamp (since the animation has begun)
- `CoroutineYield.WaitUntilPredicate`: Waiting until a condition is satisfied
- (static) `CoroutineYield.Suspend`: Suspending an update without influencing the flow of time
This allows mixing both serial and parallel execution.