# How to only play animation when deleting and creating new object

**URL:** https://discourse.processing.org/t/how-to-only-play-animation-when-deleting-and-creating-new-object/37643
**Category:** Coding Questions
**Created:** [June 19, 2022, 8:16pm UTC](https://discourse.processing.org/t/how-to-only-play-animation-when-deleting-and-creating-new-object/37643 "2022-06-19T20:16:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![acorns](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@acorns](https://discourse.processing.org/u/acorns)
#### Post date: [June 19, 2022, 8:16pm UTC](https://discourse.processing.org/t/how-to-only-play-animation-when-deleting-and-creating-new-object/37643/1 "2022-06-19T20:16:01Z")

</div>

Hi guys, I am creating a cherry blossom branch where you add a new flower object (via pressing z key) and delete flower object (via pressing m key). I want to make it before it display(), it plays a blooming animation when a new object is added, and a falling animation when an object is deleted.

How would I go about doing that? Thank you

Link to code: [p5.js Web Editor](https://editor.p5js.org/sshalim.halim68/sketches/6JMUQbr1Y)

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 19, 2022, 10:56pm UTC](https://discourse.processing.org/t/how-to-only-play-animation-when-deleting-and-creating-new-object/37643/2 "2022-06-19T22:56:34Z")

</div>

Hello @acorns,

Consider how you would animate this one flower at a time instead of in a loop.

`setup()` runs once  
`draw()` loops at 60 frames per second

Try:

- with and without background in `draw()`
- something like this in `draw()`:

```auto
flowers[counter].display();
counter++;

```

- only hints and not complete

Not a direct answer to your question… it may still gives you some ideas.

Update…

This is a simple timer that can be added to the class:

```auto
bloom() 
    {
    if (this.bb == false)
      {
      //this.tstart = millis()
      this.tstart = frameCount
      this.bb = true
      }
    else
      {
      //if(millis() < this.tstart+1000)
      if(frameCount < this.tstart+60)
        this.size += 1    
      else
        this.bb = false
      }
    }          

```

There is a `frameCount` version and a `millis()` version.

It is _very rough code_ and did work in a simplified version of your code; I used circles in place of images.

`:)`
