Multiple Instances only drawing last instance

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.

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();
    ButtonObjectClass buttonObject2 = new ButtonObjectClass();

//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;
    if (circleOver) {
    } else {
    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?

1 Like

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

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

1 Like

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

1 Like