Skip to content

Instantly share code, notes, and snippets.

@trentbrooks
Last active November 13, 2015 02:42
Show Gist options
  • Save trentbrooks/a99230cf4637b86cce98 to your computer and use it in GitHub Desktop.
Save trentbrooks/a99230cf4637b86cce98 to your computer and use it in GitHub Desktop.
C++11 lambda + std::function callbacks. eg. sequence of animations
// https://msdn.microsoft.com/en-us/library/dd293599.aspx & https://msdn.microsoft.com/en-us/library/dd293608.aspx
// sequence of tweens/animations called sequentially
tween.go(&width, 200, 1.0).onDone([&]() {
tween.go(&height, 100, 1.0).onDone([&]() {
tween.go(&target, ofVec3f(100,200), 1.0).onDone([&]() {
tween.go(&target, ofVec3f(800,400), 3.0).onDone([&]() {
tween.go(&rotation, 900, 1.0).onDone([&]() {
tween.go(&target, ofVec3f(ofGetWidth()/2, ofGetHeight()/2), 2.0);
});
});
});
});
});
// min example of tween class callback property + onDone() method...
function<void(void)> callback;
void onDone(function<void(void)> lambda) {
callback = lambda; // can now fire callback() when tween is finished
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment