Using ofxPlaylist

A Library for Dynamic Animations 

ofxPlaylist makes it easy to describe complex animations in code. It is useful, whether you want to tween values in sync or in sequence, tween stuff triggered by some user-generated event, or want to keep your update methods clean in complex projects. Think of a button that changes shape and then fades out when clicked. Or an animated character who first raises an arm and then nods its head. In the past, ofxPlaylist has animated puppets, pufferspheres and pirates. And, so I’ve been told, some people use it on iPhone projects.

Key Features 

Download 

Get the source code on github, and move it to your addons/ directory.

This includes two example projects, one of which is intended for beginners.

Example Projects 

It’s much more fun to poke around an example project and see how it all works! ofxPlaylist comes with 2 example projects. These show off some of the most useful features. Best start with a simple example. You can find it at ofxPlaylist/simpleExample.

Then move on to the advanced example. It is a massive show-off of almost everything. Think North-Korean military parade. Approach with care. If you must: ofxPlaylist/example

screenshot of advanced example
A screenshot of the advanced example app. Every click animates a random rectangle.

Use 

Look at the simple example project of how to get a basic setup running. Here’s a code snippet to show a most common use case:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// in testApp.h: 

#include "ofxPlaylist.h"

ofxPlaylist playlist1; 

// in testApp.cpp:

/* ... */

void testApp::update(){
	playlist1.update();	// this is where ofxPlaylist does its magic.
}

// ------------------------------------------------------

void testApp::mouseReleased(int x, int y, int button){
	using namespace Playlist;

	// say we want to tween the x and y values of some ofVec3f myPos

	playlist1.addKeyFrame(Action::tween(1000.f, &myPos.x, 400.f));
	// this will take 1000ms to tween myPos.x from
	// its current value to the target value 400.f

	playlist1.addKeyFrame(Action::pause(500.f));
	// will then pause 500ms

	playlist1.addKeyFrame(Action::tween(500.f, &myPos.x, 100.f));
	playlist1.addToKeyFrame(Action::tween(500.f, &myPos.y, 200.f));
	// will then take 500ms to tween myPos.x and myPos.y in sync 
	// towards 100.f and, respectively, 200.f
	// 
	// Note the use of addToKeyframe() vs. addKeyframe():
	//
	// addToKeyframe() is useful if you want to stack up Tweens,
	// so that they get executed in paralell.
}

FAQ: Is there a GUI? 

Nope. ofxPlaylist is here to create animations dynamically, when responding to user inputs.

There is, however, a yet undocumented which allows you to import AfterEffects XML timelines. This way, you get GUI and preview from AfterEffects, and the flexibility of dynamic playlists from ofxPlaylist!

If you need a GUI and want to load, edit and save static timelines within your openFrameworks app, I recommend checking out ofxTimeline by @obviousjim et al.

FAQ: Is there a way to save Playlists? 

Kinda.

FAQ: How does it work? 

Glad you asked. Let’s start with the basics, and then wade step by step into the quicksand of some more complex (and gory) details:

A Playlist is a list of Actions that need to happen in sequential order. These Actions{ (of which there are three different kinds)} are grouped together in Keyframes.

image
Anatomy of a Playlist: stack up as many actions (③) as you like to build a Keyframe (①). Push the keyframe to the end of a Playlist (②).

All Actions within a Keyframe start at the same time and execute in parallel. A Keyframe is done, when all its Actions have finished. This Keyframe is then deleted, and the next one starts.

image
A most basic Playlist: Keyframes boundaries marked in red. This will take 200ms to tween the value held by ‘a’ from 300.f to 0.f, then take 1000ms to tween ‘a’ to 50.f, then take 50ms to tween ‘a’ to 0.f.

You can push additional Keyframes to the end of a Playlist at any time. You can also clear Playlists anytime.

Each Keyframe holds one or more Actions. These can be any of the following three:

image
Types of Actions within Keyframes:
Tween,
Pause,
Event

When a Keyframe begins execution, all its Actions start in sync.

Dependencies: 

♥ openFrameworks >= 0071

License 

ofxPlaylist is released under the MIT License.


Tagged:

tutorialcode


RSS:

Find out first about new posts by subscribing to the RSS Feed


Further Posts:

Vulkan Video Decode: First Frames h.264 video island rendergraph synchronisation vulkan code
C++20 Coroutines Driving a Job System code coroutines c++ job-system
Vulkan Render-Queues and how they Sync island rendergraph synchronisation vulkan code
Rendergraphs and how to implement one island rendergraph vulkan code
Implementing Bitonic Merge Sort in Vulkan Compute code algorithm compute glsl island
Callbacks and Hot-Reloading Reloaded: Bring your own PLT code hot-reloading c assembly island
Callbacks and Hot-Reloading: Must JMP through extra hoops code hot-reloading c assembly island
How far back should the screen go? math tutorial
Earth Normal Maps from NASA Elevation Data tutorial code
Flat Shading using legacy GLSL on OSX tutorial code