Consider this example:
The tween happen in two steps:
- set x to 0, tween width to 100
- tween x to 100, tween width to 0
When tween 1 is complete, call tween 2. When 2 is complete, call 1 again to create a loop.
I tried to do it with a few addons.
ofxTween doesn’t seem to have an ‘on complete’.
ofxTweenzor and ofxTweener have ‘on complete’, but the callback only knows about the value that was tweened, nothing else. For example, when width is tweened it is not possible to know x, or anything about the rectangle.
This led me to write two functions:
//--------------------------------------------------------------
void TestScene::showRect_01(float* arg) {
rect_01.width = 0;
rect_01.x = 0;
Tweenzor::add(&rect_01.width, rect_01.width, 100, 0.f, 2.f, EASE_IN_OUT_QUART);
Tweenzor::addCompleteListener(Tweenzor::getTween(&rect_01.width), this, &TestScene::hideRect_01);
}
//--------------------------------------------------------------
void TestScene::hideRect_01(float* arg) {
Tweenzor::add(&rect_01.x, rect_01.x, 100, 0.f, 2.f, EASE_IN_OUT_QUART);
Tweenzor::add(&rect_01.width, rect_01.width, 0, 0.f, 2.f, EASE_IN_OUT_QUART);
Tweenzor::addCompleteListener(Tweenzor::getTween(&rect_01.x), this, &TestScene::showRect_01);
}
This works, but it is not dynamic at all.
What if I want to tween 100 rectangles? Not just all at once but with a 0.1 second delay between them, for example.
Is it possible to pass a pointer to the rectangle in the callback function?
I am used to GreenSock TweenMax and it has ‘onCompleteParams’. I am not sure if something like that would be possible / good practice in C++.
In other words: what would be the best way to chain tweens?