Tweeny is a modern C++ inbetweening library designed for creating complex animations for games and other interactive software. It provides a type-safe, fluent API for declaring interpolations (tweens) of any type that supports arithmetic operations.
Key Features
- Type-safe and modern: Leverages C++17 features for compile-time type checking
- Fluent builder API: Intuitive method chaining for tween creation
- Multi-value tweens: Animate multiple values simultaneously (e.g., RGB colors, 3D positions)
- Heterogeneous types: Mix different numeric types in a single tween
- Rich easing library: Includes 30+ built-in easing functions
- Keyframe animations: Create complex multi-segment animations
- Event system: React to tween lifecycle events (step, seek, jump, update, complete, keyframeEnter, keyframeLeave)
- Header-only: Simple integration with no linking required
- Zero dependencies: Only requires a C++17 compiler
Quick Start
- Note
- Coming from Tweeny 3.x? Check out the migration guide!
#include <tweeny/tweeny.h>
int main() {
for (int i = 0; i < 60; i++) {
}
.build();
.during(60U)
.build();
.build();
return 0;
}
auto step(int32_t frames) -> tween_value_t
Advances or rewinds the animation by a frame delta.
A tween represents an animation between keyframes.
Definition tween.h:68
tweeny_builder< true, FirstValue, RemainingValues... > to(const FirstValue &firstComponent, const RemainingValues &... remainingComponents) &
Adds a target keyframe to the tween.
Definition tweeny.h:109
tweeny_builder & during(FrameCountsType... frame_counts)
Specifies per-component frame durations for the last keyframe segment.
Definition tweeny.h:245
tweeny_builder & via(EasingFunctionTypes... easing_functions)
Specifies per-component easing functions for the last keyframe segment.
Definition tweeny.h:198
constexpr detail::quadraticInOutEasing quadraticInOut
Quadratic polynomial easing with gentle acceleration and deceleration.
Definition easing.h:1069
constexpr detail::linearEasing linear
Linear easing function with constant velocity throughout the animation.
Definition easing.h:956
constexpr detail::bounceOutEasing bounceOut
Bounce easing simulating a ball dropping and bouncing to rest.
Definition easing.h:259
Contains all built-in easing functions for controlling animation curves.
Definition by-name.h:32
tweeny_builder< false, FirstValue, RemainingValues... > from(FirstValue firstComponent, RemainingValues... remainingComponents)
Creates a new tween builder starting from the specified value(s).
Definition tweeny.h:347
Visit the manual for a more in-depth explanation of the library.
API Reference
The most important parts of the API are:
Common Patterns
Basic Animation
}
auto progress() const -> float
Returns the animation completion percentage.
Seeking and Jumping
auto seek(uint32_t target_frame) -> tween_value_t
Seeks to a specific frame in the animation.
auto jump(std::size_t target_key_frame) -> tween_value_t
Jumps to a specific keyframe index.
Event Listeners
});
std::cout << "Entered keyframe " << evt.key_frame << std::endl;
});
auto on(detail::event::step_t, Callback &&cb) -> void
Registers a callback for step() events.
auto peek() const -> tween_value_t
Returns the current interpolated value without changing state.
@ ok
Continue receiving events.
Definition detail/event.h:108
constexpr detail::event::step_t step
Event triggered after each step() call.
Definition event.h:83
Event data passed when entering a new keyframe.
Definition detail/event.h:81
Multi-Value Tweens
auto [r, g, b] = color.step(1);
.during(60U)
.build();
.build();
Resources
License
Tweeny is licensed under the MIT License. See the LICENSE file in the repository for details.