Been messing around with
Ani lately and it's a fantastic little library. Inspecting the example Ani_Callback and adding a delay to the instantiation of diameterAni
doesn't delay the onStart callback invoked. I expected that it would — is there a way to account for this?
e.g:
- /**
- * shows how to use the callback features onStart and onEnd
- *
- * MOUSE
- * click : set end of animation and trigger a new one
- */
- import de.looksgood.ani.*;
- float x = 256;
- float y = 256;
- int diameter = 50;
- Ani diameterAni;
- void setup() {
- size(512,512);
- smooth();
- noStroke();
- // Ani.init() must be called always first!
- Ani.init(this);
- // define a Ani with callbacks, specify the method name after the keywords: onStart and onEnd
- diameterAni = new Ani(this, 1.5, 2, "diameter", 150, Ani.EXPO_IN_OUT, "onStart:itsStarted, onEnd:newRandomDiameter");
- // side info: it's also possible to define this in a static way
- //diameterAni = Ani.to(this, 1.5, "diameter", 150, Ani.EXPO_IN_OUT, "onStart:itsStarted, onEnd:newRandomDiameter");
- }
- void draw() {
- background(255);
- fill(0);
- ellipse(x,y,diameter,diameter);
- }
- void mouseReleased() {
- Ani.to(this, 1.5, "x", mouseX, Ani.ELASTIC_OUT);
- Ani.to(this, 1.5, "y", mouseY, Ani.ELASTIC_OUT);
- // start diameterAni
- diameterAni.start();
- }
- // there are two possiblities to declare the methods for the callbacks:
- // without any parameters or with one parameter of type Ani
- // called onStart of diameterAni animation
- void itsStarted() {
- println("diameterAni started");
- }
- // called onEnd of diameterAni animation
- void newRandomDiameter(Ani theAni) {
- float end = theAni.getEnd();
- float newEnd = end + random(-20,20);
- theAni.setEnd(newEnd);
- println("diameterAni finished. current end: "+end+" -> "+"new end: "+newEnd);
- }
Not sure what a good workaround would be? Calling ani.isDelaying() until it's false?
1