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

**URL:** <https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719>\
**Category:** Libraries\
**Created:** [November 26, 2020, 2:53am UTC](https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719 "2020-11-26T02:53:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AbleYudada](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ableyudada/32/14190_2.png) [@AbleYudada](https://discourse.processing.org/u/AbleYudada)\
**Post date:** [November 26, 2020, 2:53am UTC](https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719/1 "2020-11-26T02:53:37Z")

</div>

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！

```auto
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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![AbleYudada](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ableyudada/32/14190_2.png) [@AbleYudada](https://discourse.processing.org/u/AbleYudada)\
**Post date:** [November 26, 2020, 2:54am UTC](https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719/2 "2020-11-26T02:54:38Z")

</div>

I am sure I have the correct library

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 26, 2020, 3:12am UTC](https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719/3 "2020-11-26T03:12:25Z")

</div>

> [@AbleYudada](#):
>
> `bodyloopingGif = new Gif(this, "1.gif");`

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

---

<div class="post-metadata">

**Author:** ![AbleYudada](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ableyudada/32/14190_2.png) [@AbleYudada](https://discourse.processing.org/u/AbleYudada)\
**Post date:** [November 26, 2020, 6:44am UTC](https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719/4 "2020-11-26T06:44:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 1, 2020, 3:45pm UTC](https://discourse.processing.org/t/the-constructor-gif-bodycreate-particle-string-is-undefined/25719/6 "2020-12-01T15:45:39Z")

</div>

> [@AbleYudada](#):
>
> , I want to create an array of unknown number to store gifs,

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

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

> [@File Listing Order](https://discourse.processing.org/t/file-listing-order/7148/41):
>
> [Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html#sort(java.lang.Object[])](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html#sort(java.lang.Object%5B%5D)) static final String PICS\_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp"; static final float FPS = .25; PImage[] images; void setup() { size(1200, 600); frameRate(FPS); imageMode(CENTER); final File dir = dataFile(""); println(dir); String[] imagePaths = {}; int imagesFound = 0; if (dir.isDirectory()) { imagePaths = listPaths(dir.getPath(), "files", "recursi…
