Ani icon indicating copy to clipboard operation
Ani copied to clipboard

There is no public this() method in the class de.looksgood.ani.Ani

Open julsgud opened this issue 9 years ago • 7 comments

When using Ani in classes and using a bang() or similar method, the applet freezes on occasion. This happened in my own sketch but I was able to reproduce the error in the Ani_in_Classes_Bang example that comes with the library as well. The error is reported at the end of the bang method in the Cirlce class.

import de.looksgood.ani.*;

Cirlce cirlce;

void setup() {
  size(512, 512);
  smooth();
  noStroke();
  textAlign(CENTER);

  // Ani.init() must be called always first!
  Ani.init(this);
  cirlce = new Cirlce();
}

void draw() {
  background(255);
  cirlce.draw();
}

void keyReleased() {
  if (key == ' ') cirlce.bang();
}

class Cirlce {
  float x = random(0, width);
  float y = random(0, height);
  color c = color(0);

  Ani diameterAni;
  float diameterStart = 200;
  float diameterEnd = 5;
  float diameter = diameterStart;
  float duration = 0.9;

  Cirlce() {
    // diameter animation
    diameterAni = new Ani(this, duration, "diameter", diameterEnd);
    diameterAni.pause();
    diameter = diameterEnd;
  }

  void bang() {
    diameter = diameterStart;
    diameterAni.seek(0);
    diameterAni.resume();
'Ani_in_Classes_Bang:54:0:54:0: RuntimeException: There is no public this() method in the class de.looksgood.ani.Ani'
  }

  void draw() {
    fill(c);
    ellipse(x, y, diameter, diameter);
  }
}

Thanks!

julsgud avatar Sep 27 '16 14:09 julsgud

Apparently method resume() can't be invoked when the Ani isEnded(). Maybe replace pause() w/ end() and resume() w/ start()? :bulb:

GoToLoop avatar Sep 27 '16 17:09 GoToLoop

You are right! The following works properly. The only downside is that you are are starting with the ended animation, which in some cases may be undesirable. Here is what works, does not throw previous error.

In constructor:

Cirlce() {
    // diameter animation
    diameterAni = new Ani(this, duration, "diameter", diameterEnd);
    diameterAni.end();
  }

Bang method:

void bang() {
    diameter = diameterStart;
    diameterAni.start();
  }

Thanks! The idea of using pause/resume/seek is great though, it helps you prep an Ani in the state that you want. Would be great to see that refactored to be able to restart when a Ani has ended.

julsgud avatar Sep 28 '16 14:09 julsgud

You can always check for isEnded() or isPlaying() before invoking resume(). :star2:

GoToLoop avatar Sep 28 '16 18:09 GoToLoop

Hi @julsgud Thanks for the bug report and pointer! I can confirm that this is a bug :( Will try to fix it with the next maintenance update (might take some time), as Ani is no longer heavily under development. P5js is the future! :) Please use in the meantime the workaround of @GoToLoop. Cheers! All the best, Benedikt

b-g avatar Oct 04 '16 08:10 b-g

Hey @b-g! @GoToLoop 's workaround does the job pretty well! Great to hear you are placing your future bets on p5js. Any plans for an Ani for p5js? Would love to help/support making that happen. Woop! Best, Juls

julsgud avatar Oct 07 '16 19:10 julsgud

Hi @julsgud, Yes I think javascript is one of the main leads for the future of creative coding in terms of technicalities ... However there are so many animation libraries in javascript that I'm not convinced whether it is a good idea / worth the effort to port Ani to JS. Or what do you think?

https://github.com/tweenjs/tween.js/ https://greensock.com/tweenlite https://github.com/juliangarnier/anime ...

b-g avatar Oct 09 '16 08:10 b-g

Hey @b-g , I have to say I agree. It also seems that tween.js has a similar approach to Ani declarations, great to have that simplicity there too. Will start doing some tests to see how well they play with p5js. Thanks for sharing these!

julsgud avatar Oct 09 '16 18:10 julsgud