# How to make an animation appear for multiple seconds when collison happens?

**URL:** <https://discourse.processing.org/t/how-to-make-an-animation-appear-for-multiple-seconds-when-collison-happens/15698>\
**Category:** Coding Questions\
**Created:** [November 21, 2019, 5:53pm UTC](https://discourse.processing.org/t/how-to-make-an-animation-appear-for-multiple-seconds-when-collison-happens/15698 "2019-11-21T17:53:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![legutierrez1](https://avatars.discourse-cdn.com/v4/letter/l/58f4c7/32.png) [@legutierrez1](https://discourse.processing.org/u/legutierrez1)\
**Post date:** [November 21, 2019, 5:53pm UTC](https://discourse.processing.org/t/how-to-make-an-animation-appear-for-multiple-seconds-when-collison-happens/15698/1 "2019-11-21T17:53:36Z")

</div>

Hello my name is Julio and i’m an undergraduate student that is new to processing.

My question is about how can i make a variable inside of a collision appear for multiple seconds.

The code part i need help with is the following, I underlined the part that i need to happen for multiple seconds:

```auto
  if (missile2.x >= paddle2.x && missile2.x <= paddle2.x + paddle2.w && missile2.y >= paddle2.y && missile2.y <= paddle2.y + paddle2.h)
  {
    **image( up[frameCount%14], 300, 400 );**
    lives += 1;
  }

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 21, 2019, 8:31pm UTC](https://discourse.processing.org/t/how-to-make-an-animation-appear-for-multiple-seconds-when-collison-happens/15698/2 "2019-11-21T20:31:30Z")

</div>

Hello and welcome to this forum!

Great to have you here.

instead of using image( up[frameCount%14], 300, 400 ); inside the if, set a boolean flag explosionIsOn (or whatever name you choose) to `true` there and evaluate explosionIsOn separately in draw() and show the explosion there.

And you can use a timer to end the explosion

Chrisir

```auto
boolean explosionIsOn = false;
int timer; 

void setup() {
  size(1200, 600);
  background(0);
}

void draw() {
  background(0); 

  if (explosionIsOn) {
    text("explosion", 211, 211);
    if (millis() - timer > 930) { // end explosion
      explosionIsOn = false;
    }
  }
}

void mousePressed() {
  explosionIsOn = true; // Start explosion
  timer=millis();
}

```
