Making an object appear multiple times when required

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

for(int i = 0;i<redorb.length;i++){
redorb[i] = new Redorb();
for(int i = 0;i<redorb.length;i++){
//todo flag
  health --;

class Redorb{
  int redx = int(random(30,750));
  int redy = int(random(30,750));
  void redorb(){
1 Like

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();

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

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


1 Like