b-g / Ani

A lightweight animation library for the programming environment Processing
79 stars 13 forks source link

onEnd does not find named method #21

Open mrbbp opened 3 weeks ago

mrbbp commented 3 weeks ago

### Ani Debug -> Error @ AniCore -> setCallbackMethods(). Can't find a method of name: finAnimation

import de.looksgood.ani.*;

PVector[] liste;  // utilisation d'un tableau comme dans l'algorithme fourni
float step = 100;
boolean animationEnCours = false;
PVector[] cibles = new PVector[4];
Ani pointAni;

void setup() {
  size(800, 800);
  Ani.init(this);
  step= width/2;
  // Initialisation du tableau de points
  liste = new PVector[4];
  liste[0] = new PVector(random(width/2), random(height/2));
  liste[1] = new PVector(random(width/2) + step, random(height/2));
  liste[2] = new PVector(random(width/2) + step, random(height/2) + step);
  liste[3] = new PVector(random(width/2), random(height/2) + step);

  // Premier tirage de points
  nouveauxPoints();
}

void draw() {
  background(255);

  // Dessiner le polygone
  fill(200, 100, 100, 100);
  beginShape();
  for (PVector p : liste) {
    vertex(p.x, p.y);
  }
  endShape(CLOSE);

  // Dessiner les points
  fill(0);
  for (PVector p : liste) {
    ellipse(p.x, p.y, 8, 8);
  }
}

void nouveauxPoints() {
  if (!animationEnCours) {
    animationEnCours = true;

    // Création des nouveaux points cibles selon l'algorithme fourni

    cibles[0] = new PVector(random(width/2), random(height/2));
    cibles[1] = new PVector(random(width/2) + step, random(height/2));
    cibles[2] = new PVector(random(width/2) + step, random(height/2) + step);
    cibles[3] = new PVector(random(width/2), random(height/2) + step);

    // Animation de chaque point
    for (int i = 0; i < liste.length; i++) {
      final int index = i;

      // Animation X
      pointAni = Ani.to(liste[i], 2.0f, "x", cibles[i].x, Ani.ELASTIC_OUT);

      // Animation Y avec callback sur le dernier point
      if (i == liste.length - 1) {
        pointAni = Ani.to(liste[i], 2.0f, "y", cibles[i].y, Ani.ELASTIC_OUT, "onEnd:finAnimation");
      } else {
        pointAni = Ani.to(liste[i], 2.0f, "y", cibles[i].y, Ani.ELASTIC_OUT);
      }
    }
  }
}

void finAnimation() { // <- finAnimation is Here
  animationEnCours = false;
  for (int i = 0; i < liste.length; i++) {
    liste[i].x = cibles[i].x;
    liste[i].y = cibles[i].y;
  }
  nouveauxPoints();  // Lance automatiquement la prochaine animation
}

what i'm doing wrong?

Macos 14.7, Processing 4.3, Ani 2.7

mrbbp commented 6 days ago

hello! anybody here?