# Multiple Instances only drawing last instance

**URL:** <https://discourse.processing.org/t/multiple-instances-only-drawing-last-instance/16186>\
**Category:** Coding Questions\
**Created:** [December 6, 2019, 6:13pm UTC](https://discourse.processing.org/t/multiple-instances-only-drawing-last-instance/16186 "2019-12-06T18:13:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://discourse.processing.org/u/Andrew)\
**Post date:** [December 6, 2019, 6:13pm UTC](https://discourse.processing.org/t/multiple-instances-only-drawing-last-instance/16186/1 "2019-12-06T18:13:42Z")

</div>

I’m just getting started with Processing (3.5.3), and so far it’s been pretty fun. However, I’ve hit a snag, and even after researching for a couple hours I still can’t figure it out. I try to create two instances of circle with different parameters, but the last circle is the only one shows up.

```auto
int circleX, circleY; // Position of circle button
int circleSize = 50; // Diameter of circle
color circleColor, baseColor, circleHighlight, currentColor;
boolean circleOver = false;

void settings() {
  size(500, 500);
}

void setup() {
}

void draw() {
    ButtonObjectClass buttonObject = new ButtonObjectClass();
    buttonObject.circleButton(255,255,0,-100,-10);
    ButtonObjectClass buttonObject2 = new ButtonObjectClass();
    buttonObject2.circleButton(255,0,0,100,10);
}

//Setting up the buttton class
class ButtonObjectClass{
  void circleButton(int r, int g, int b, int xPos, int yPos)
  {
    circleColor = color(r,g,b);
    circleHighlight = color(r/2,g/2,b/2);
    baseColor = color(102);
    circleX = width/2+circleSize/2+xPos;
    circleY = height/2+yPos;
    ellipseMode(CENTER);
    update();
    
    background(currentColor);
  
    if (circleOver) {
      fill(circleHighlight);
    } else {
      fill(circleColor);
    }
    stroke(0);
    ellipse(circleX, circleY, circleSize, circleSize);
    
  }
}

//Checks if mouse is hovering over button
void update() {
  if ( overCircle(circleX, circleY, circleSize) ) {
    circleOver = true;
  } 
  else {
    circleOver = false;
  }
}

//Checks if mouse is pressed and prints "Button Pressed"
void mousePressed() {
  if (circleOver) {
    currentColor = circleColor;
    println("Button Pressed");
  }
}

//Determines actual size and location of button to determine if the mouse is touching it
boolean overCircle(int x, int y, int diameter) {
  float disX = x - mouseX;
  float disY = y - mouseY;
  if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
    return true;
  } else {
    return false;
  }
}

```

Can someone explain to me what I’m doing wrong and how to fix it?

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 6, 2019, 7:38pm UTC](https://discourse.processing.org/t/multiple-instances-only-drawing-last-instance/16186/2 "2019-12-06T19:38:52Z")

</div>

You‘re setting background() within the constructor of the class, so your Code does this :

Create ButtonObject  
Background  
Draw Ellipse  
Create ButtonObject2  
Background \<- this one „deletes“ the other ellipse.  
Draw Ellipse2.

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://discourse.processing.org/u/Andrew)\
**Post date:** [December 6, 2019, 7:40pm UTC](https://discourse.processing.org/t/multiple-instances-only-drawing-last-instance/16186/3 "2019-12-06T19:40:57Z")

</div>

Oh, man! That was sooo simple, thank you!
