# Making an object appear multiple times when required

**URL:** <https://discourse.processing.org/t/making-an-object-appear-multiple-times-when-required/20236>\
**Category:** Coding Questions\
**Created:** [April 28, 2020, 12:15pm UTC](https://discourse.processing.org/t/making-an-object-appear-multiple-times-when-required/20236 "2020-04-28T12:15:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captainmajere](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@captainmajere](https://discourse.processing.org/u/captainmajere)\
**Post date:** [April 28, 2020, 12:15pm UTC](https://discourse.processing.org/t/making-an-object-appear-multiple-times-when-required/20236/1 "2020-04-28T12:15:25Z")

</div>

I am trying to make a game about consuming balls and I have yet to find a solution for these two problems.  
1- Making collision a one time thing without using a flag  
2-Making my redorbs spawn exponantially after consuming one

```auto
for(int i = 0;i<redorb.length;i++){
redorb[i] = new Redorb();
.......
for(int i = 0;i<redorb.length;i++){
if(collide(redorb[i].redx,redorb[i].redy,posx,posy)==true){
//todo flag
  health --;
  mult++;
  redorb[i].redorb();
}
 }
......

class Redorb{
  int redx = int(random(30,750));
  int redy = int(random(30,750));
  void redorb(){
reds.background(255,0);
reds.fill(255,0,0);
reds.ellipse(redx,redy,10,10);  
}}

```

---

<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:** [April 30, 2020, 11:41am UTC](https://discourse.processing.org/t/making-an-object-appear-multiple-times-when-required/20236/2 "2020-04-30T11:41:58Z")

</div>

maybe in your case instead of using an array, use an ArrayList since you can more easily add and remove items.

before setup()

ArrayList listOrbs = new ArrayList();

> [@captainmajere](#):
>
> Making collision a one time thing without using a flag

why not use a flag? Or you can remove them, which is a bit tricky with an ArrayList (for loop backwards)

> [@captainmajere](#):
>
> 2-Making my redorbs spawn exponentially after consuming one

OK, you can use add() to add 2 new orbs to the list. Use the pos of the initial one and also the direction with a small deviation

Chrisir
