Tweeny 4.1.0
A Tweening library for modern C++
Loading...
Searching...
No Matches
Introduction

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() {
// Simple tween from 0 to 100 over 60 frames
auto tween = tweeny::from(0).to(100).during(60U).build();
// Step through the animation
for (int i = 0; i < 60; i++) {
int value = tween.step(1);
// Use value...
}
// Multi-value tween (e.g., for RGB color)
auto color = tweeny::from(255, 0, 0)
.to(0, 255, 0)
.during(120U)
.build();
// Tween with easing
auto smooth = tweeny::from(0.0f)
.to(100.0f)
.during(60U)
.build();
// Multi-segment animation with keyframes
auto complex = tweeny::from(0)
.to(50).via(easing::linear).during(30U)
.to(100).via(easing::bounceOut).during(30U)
.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 tween = tweeny::from(0.0f).to(1.0f).during(60U).build();
while (tween.progress() < 1.0f) {
float alpha = tween.step(1);
// Render with alpha...
}
auto progress() const -> float
Returns the animation completion percentage.

Seeking and Jumping

auto tween = tweeny::from(0).to(100).during(100U).build();
// Jump to specific frame
tween.seek(50U);
// Step backward (negative delta)
tween.step(-10);
// Jump to a keyframe by index
tween.jump(0); // Jump back to first keyframe
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

auto tween = tweeny::from(0).to(100).during(60U).build();
// Listen for step events
std::cout << "Value: " << tween.peek() << ", Progress: " << tween.progress() << std::endl;
});
// Listen for keyframe transitions
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

// Animate RGB color
auto color = tweeny::from(255, 0, 0).to(0, 255, 0).during(120U).build();
auto [r, g, b] = color.step(1);
// Different easing per component
auto position = tweeny::from(0.0f, 0.0f)
.to(100.0f, 50.0f)
.during(60U)
.build();
// Different duration per component
auto mixed = tweeny::from(0, 0)
.to(100, 200)
.during(60U, 120U) // X completes in 60 frames, Y in 120
.build();

Resources

License

Tweeny is licensed under the MIT License. See the LICENSE file in the repository for details.