ofxTweenzor is a addon for OpenFrameworks that allows for tweening values over time. I began developing the addon because I started using OF on the iPhone and I wanted a little transition here and there. I started programming and someone mentioned ofxTween. I checked it out and turns out that it runs on poco events and right now poco is not included in the iPhone build. Being a Flash developer, I wanted some tweens and I wanted to get familiar with events in C++ and how they could be handled, which took a little getting used to. I learned a great deal about pointers and events in C++, and I still have a way to go.

Hopefully someone will find this useful, and any questions or comments are welcome.

The easing equations are from both Robert Penner and the Tweener class by Zeh Fernando, Nate Chatellier and Arthur Debert.

Download ofxTweenzor

The source includes a basic example file, and most of the following is included in there.

Don’t forget to initialize the class.

void testApp::setup() {

Tweenzor::init();

}

Remember to update the class in one place only, since it is a singleton

void testApp::update() {

Tweenzor::update();

}

——————————————————-

Adding a tween

// add a tween that uses frames as time, by passing in an int for $delay and $duration
Tweenzor::add(float* $property, float $begin, float $end, int $delay, int $duration, int $easeType);

// to add a tween measured in seconds, pass in a float for delay and duration //
Tweenzor::add(float* $property, float $begin, float $end, float $delay, float $duration, int $easeType);

——————————————————-

If you would like to call a function when a tween is done, you can add a listener to the tween for when it is complete. We can get the tween by using the getTween function of Tweenzor. Tweenzor indexes the tweens based on the property you initially use to create the tween.

Tweenzor::getTween( property )->addListener(  Tween::COMPLETE, this, &testApp::onCompleteFunction );

——————————————————-

OnUpdate calls are also available, to add a Listener, do the following

Tweenzor::getTween( property )->addListener(  Tween::UPDATE, this, &testApp::onUpdateFunction );

——————————————————-

The setTimePct function available on tweens is useful for getting values at certain times

This function is best used with frames.

float property = 0.f;
Tweenzor::getTween( &property )->setTimePct( .5f );
// we must update the property to make sure, in case the update function is not called on the function //
Tweenzor::getTween( &property )->updateProperty();

float value = Tweenzor::getTween( &property )->getPropertyValue();
float pct = Tweenzor::getTween( &
property )->getPropertyPct();