b-g / Ani

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

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

Open julsgud opened 7 years ago

julsgud commented 7 years ago

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!

GoToLoop commented 7 years ago

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

julsgud commented 7 years ago

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.

GoToLoop commented 7 years ago

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

b-g commented 7 years ago

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

julsgud commented 7 years ago

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

b-g commented 7 years ago

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 ...

julsgud commented 7 years ago

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!