overlaping objects:

edited December 2016 in Questions about Code

hi people! i'm trying to make a working clock that adds a second when the M.seconds reach 60, and a minute when seconds reach 60. right now, it all adds up pretty well. only problem is that numbers overlap. how can I make them replace each other instead of creating new ones?

    int H = 0;
    int h = 0;
    int M = 0;
    int m = 0;
    int S = 0;
    int s = 0;
    void setup() {
      size(100, 50);
    }

    void draw() {
      if (s != 9) {
        s++;
      } else if (S != 5) {
        S++;
        s = 0;
      } else if (m != 9) {
        m++;
        S = 0;
      } else if (M != 5) {
        M++;
        m = 0;
      } else if (h != 60) {
        h++;
        M = 0;
      } else if (H != 60) {
        H++;
        h = 0;
      }

      textSize(22);
      text(H+h+";"+M+m+";"+S+s, 10, 33);
    }

thanks in advance ;)

Tagged:

Answers

  • I guess removing all the else should work. :-/

  • edited December 2016 Answer ✓

    You just need to add a background call to the start of draw. Quite obviously.
    Add background(255); to draw(), and it should come before text() (preferably at the start of draw()). And send the textSize() to setup().

Sign In or Register to comment.