# How to play Gif after mousePressed?

**URL:** <https://discourse.processing.org/t/how-to-play-gif-after-mousepressed/20718>\
**Category:** Libraries\
**Created:** [May 10, 2020, 5:06pm UTC](https://discourse.processing.org/t/how-to-play-gif-after-mousepressed/20718 "2020-05-10T17:06:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neev](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Neev](https://discourse.processing.org/u/Neev)\
**Post date:** [May 10, 2020, 5:06pm UTC](https://discourse.processing.org/t/how-to-play-gif-after-mousepressed/20718/1 "2020-05-10T17:06:45Z")

</div>

Hi guys, I’m pretty new to Processing but I am using it for my college project. I’m having trouble getting a gif to load after the mouse has been pressed. I know that after the mouse is pressed once it takes a picture but I was wondering if there was a way to have the gif load after the mouse is pressed and the camera stops?

```auto
import processing.video.*;

Capture cam;

PImage facescan;

boolean hasClicked;

void setup() {
  size(1920, 1080);
  background(255);
  facescan = loadImage("facescan.gif"); 

  String[] cameras = Capture.list();
  
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    
    cam = new Capture(this, cameras[0]);
    cam.start();     
  }      
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  
  image(cam, 0, 0, 800, 600);
}

void mousePressed(){
  image(facescan, 1920, 1080);
  cam.stop();
}

```

```auto

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 12, 2020, 12:07am UTC](https://discourse.processing.org/t/how-to-play-gif-after-mousepressed/20718/2 "2020-05-12T00:07:35Z")

</div>

> [@Neev](#):
>
> getting a gif to load after the mouse has been pressed.

Is the gif animated or static?

Do you want it to display only only while the mouse is being pressed, or from then on?

---

<div class="post-metadata">

**Author:** ![Neev](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Neev](https://discourse.processing.org/u/Neev)\
**Post date:** [May 12, 2020, 2:27pm UTC](https://discourse.processing.org/t/how-to-play-gif-after-mousepressed/20718/3 "2020-05-12T14:27:15Z")

</div>

It’s a moving gif.  
Essentially what I’m looking to do is once you click your picture is taken, a gif loads and then the tint on the camera changes so the image is in a different colour after the gif finishes playing.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 12, 2020, 4:04pm UTC](https://discourse.processing.org/t/how-to-play-gif-after-mousepressed/20718/4 "2020-05-12T16:04:29Z")

</div>

One method is to load a list of static images as your animation frames.

[https://processing.org/examples/animatedsprite.html](https://processing.org/examples/animatedsprite.html)

Another is to install the GifAnimation library.

- [https://forum.processing.org/two/discussion/24885/load-a-moving-gif](https://forum.processing.org/two/discussion/24885/load-a-moving-gif)
