Skip to content

Sven-vh/type-tween

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alt text


Single header C++ Tweening file

What is it

A simple "library" that allows the user to create tweens easily. It supports:

  • From | Start value
  • To | End value
  • Duration | Tween time
  • Delay | Wait time
  • Easing | See Easing
  • Yoyo | tween back in reverse
  • Repeat | When done, keep playing
  • OnUpdate | Update callback
  • OnComplete | Complete callback

How to integrate

The Only thing you need is TypeTween.hpp. Download it and include it anywhere in your project.

image

How to use

/* Manager that holds all the tweens */
TypeTween::Manager manager;

/* Specify the type */
TypeTween::Tween<float> tween;

/* Set values of tween */
tween.From(startValue).
	To(endValue).
	Duration(duration).
	Easing(ease).
	Yoyo(yoyo).
	Repeat(repeat)
	.OnUpdate(
		[](const float& _value, float t) {
			std::cout << "Value: " << _value << " Time: " << t << std::endl;
		}
	).OnComplete(
		[](const float& value) {
			std::cout << "Done" << std::endl;
		}
	);

/* Add it to the manager */
manager.AddTween(tween);

/* In your main loop, update the manager */
while(true){
	float deltaTime = 1.0f/60.0f;
	manager.Update(deltaTime)
}

Example

418356808-9423c988-cbf9-4073-895f-090b2c5edc1c

Types

Since the tween is templated, any type with a +, -, and * operator will work.

It also contains pointer support. The pointer gets updated, so there is no need for an OnUpdate callback.

Easing

As of right now, it currently supports these easings: Screenshot_512 Source easings.net

Example

This repo contains an example.sln. This is just a simple showcase of how to use it and check if everything works as expected.

tweening

Contributions & Issues

It started as a simple header that I kept re-using. So I decided to share it here! Feel free to contribute, make issues, make pr's, if you have any suggestions!

About

Single header C++ Tweening system

Resources

License

Stars

Watchers

Forks

Languages