Hello. I’m trying to use the Ani library to orchestrate a sketch that contains several “sub-modes” that have their own timelines and display methods. Essentially, I would like the master sketch to run a sequence similar to:
-
Do some intro stuff
-
Mode 1 plays: start its own sequence, reach the end
-
Do some transition stuff
-
Mode 2 plays: start its own sequence, reach the end
-
Do some outro stuff
The “modes” being their own classes with their own display() methods that are called by the master draw()
when necessary. There are several “modes” but for the sake of minimal reproducible error here I’m showing only one Mode
class.
I’m successfully running an AniSequence
inside my Mode
class but I get this error: ### Ani Debug -> Error @ AniCore -> dispatchOnFinish(). java.lang.reflect.InvocationTargetException
as the Mode’s own sequence reaches its end and tries to tell the master AniSequence
to resume()
.
Any ideas?
Thank you very much!
See code below:
import de.looksgood.ani.*;
import de.looksgood.ani.easing.*;
Mode mode1;
AniSequence score;
int foo;
void setup() {
Ani.init(this);
size(1000, 500);
score = new AniSequence(this);
foo = 0;
mode1 = new Mode(this, score);
score.beginSequence();
//do one first step, then start mode1
score.add(Ani.to(this, 1, "foo", 255, Ani.LINEAR, mode1, "onEnd:enter"));
// and pause the master score.
score.add(Ani.to(this, 1, "foo", 255, Ani.LINEAR, "onStart:pauseMasterScore"));
//when master score is resumed do this
score.add(Ani.to(this, 2, "foo", 0, Ani.LINEAR));
score.endSequence();
score.start();
}
void draw() {
background(0);
println("master score step = ", score.getStepNumber());
mode1.display();
}
void loop() {
score.start();
}
void pauseMasterScore() {
score.pause();
println("##################### MASTER SCORE PAUSED");
}
class Mode {
AniSequence mScore;
AniSequence mParentScore;
int mPos = 0;
Mode(PApplet _p, AniSequence _ps) {
mParentScore = _ps;
mScore = new AniSequence(_p);
mScore.beginSequence();
mScore.add(Ani.to(this, 2, "mPos", 50, Ani.LINEAR, "onEnd:resumeMasterScore")); //do something then resume the master score
mScore.endSequence();
}
void enter() {
mScore.start();
println("##################### SUB SCORE STARTED");
}
void display() {
println("sub score step ", mScore.getStepNumber());
fill(150, 0, 0);
rect(mPos, mPos, 100, 100);
}
void resumeMasterScore() {
mParentScore.resume();
println("master score resumed");
}
}