ofxTween callback, signal or event?

How does one capture information from tweens using the (further excellent) tweening addon ofxTween?

For example, i’d like to know outside of the main ofxApp update / draw methods when a tween is completed, so i can fire some method, switch a boolean etc.

When you test for example for someOfxTween.isCompleted() inside your main draw() function, it will be true allways after the tween is finished. What i need is something like a signal, callback, event or other pub/sub system for one-time updates.

How does one achieve this using the ofxTween addon, or in OpenFrameworks in general?

Right now i have solved my problem using a unique situation and setting another boolean flag to ‘simulate’ an initial event, like so:

// if truck animation is completed, initial coindump
if(ofGetFrameNum() == 300 && dumptruck.isCompleted()) {
    initialCoinDrop = true;
}

if(initialCoinDrop == true) {
    dumpCoins = true;
    initialCoinDrop = false;
}

if(dumpCoins == true && particles.size() < 50) {
    dropCoin(true);
    if(particles.size() == 50) {
        dumpCoins = false;
        laterCoinDrop = true;
    }
}

where

ofGetFrameNum() == 300

is my ‘unique’ situation, which only happens once, and

if(initialCoinDrop == true) {
    dumpCoins = true;
    initialCoinDrop = false;
}

is my boolean flag switch. HORRIBLE! Please tell me there is another way. What i’d like to know is when a Tween completes, right now i only know of using ofxTween.isCompleted().
I have a love for working with the concept of Signals (Js implementation / AS3 implementation ) so if that is somehow possible, that would be grand!

Thanks!

1 Like