Why does my bubble not stop at the top?

Hi, if anyone could help me figure out why my bubble does not stop once y is greater than the height that would be great :slight_smile:

Thanks in advance.

Bubble b;

void setup() {
  size(600, 400);
  b = new Bubble();
}

void draw() {
  background(0);
  b.display();
  b.ascend();
  b.top();
}

class Bubble {

  float x;
  float y;
  float d;

  Bubble() {
    x = width/2;
    y = height;
    d = 100;
  }

  void display() {
    fill(255);
    ellipse(x, y, d, d);
  }

  void ascend() {
    y = y - 5;
  }

  void top() {
    if (y > height) {
      y = height;
    }
  }
}

1 Like

look at top()

the error is in this function

the top of the screen is 0, not height

check your if-clause

Chrisir

1 Like

Thanks so much! Now I feel stupid haha

1 Like

Hi,

Have a look a this link:
https://processing.org/tutorials/drawing/

It explains the coordinate system of processing pretty well =)

2 Likes

also the radius is 50, so it looks better when we wait until the ball completely left the screen

and also when it reappears, it reappears below the screen and slowly ascends

   if (y < -53) {
      y = height+59;
    }
1 Like

I understand it, I guess I just don’t know it very well haha. Hopefully it will come with time :slight_smile:

1 Like

Okay cool, and the below would also be correct I’m pretty sure? :slight_smile:

    if (y < -50) {
      y = height+50;
    }

I know what you mean, 50

I think it looks slightly better with 53

Nevermind

1 Like

I get you now, thanks!