The constructor Gif(bodycreate.Particle, String) is undefined

Hi everyone ,I encountered some difficulties in the code.

I want to create a new gif when I click the mouse . But it can’t work 。It said The constructor Gif(bodycreate.Particle, String) is undefined. The following is part of my code. I really need some help!

class Particle {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float r,g,b;
  float lifespan;
  Gif bodyloopingGif;
  float y;
  float easing = 0.05;

  Particle(int ID) {
    // The acceleration

      bodyloopingGif = new Gif(this, "1.gif");//The constructor Gif(bodycreate.Particle, String) is 
                                                                  //undefined   (in here)

    bodyloopingGif.loop();
    acceleration = new PVector(0, 0);
    // circel's x and y ==> range
    velocity = new PVector(0, 0);
    // apawn's position
    location = new PVector(width/2, 0);
    y = 9*height/10;
    // the circle life time
    lifespan = 255.0;
    r = random(0,255);
    g = random(0,255);
     b = random(0,255);
      location.y = y;
  }
  void run() {
    //update();
    display();
  }
  void update(float yy) {
        float y = yy;
    if(location.y != y)
    {
     
     float dy = y - location.y;
      location.y += dy * easing;
    }
    //lifespan-=1.0;
  }
 
  boolean isDead() {
    if (lifespan <= 0) {
      return true;
    } else {
      return false;
    }
  }
  void display() {
    // border
    stroke(0, lifespan);
    // border's weight
    strokeWeight(1);


    // random the circle's color

    // random the circle's color
   fill(r,g,b, lifespan);
    // draw circle
   // ellipse(location.x, location.y, 3, 3);
    rect(location.x, location.y, 100, 100);
  }
}

I am sure I have the correct library

  • The keyword this is of the datatype of the class it is in.
  • In the case above this is of the datatype Particle.
  • However Gif’s constructor demands a datatype PApplet as its 1st argument.
  • In general it is best to load assets within setup() or settings().
  • Then have our own classes request already loaded assets rather than attempting to load them on their own.

Thanks ! I think I know what you mean. By the way, I want to create an array of unknown number to store gifs, what should I do?

Don’t you know how many GIF files you’re gonna use for your sketch? :no_mouth:

You can use listPaths() and search for “.gif” extension files: :open_file_folder: