How to add +1 to variable every 10 seconds in Processing?

前端 未结 3 1443
日久生厌
日久生厌 2020-12-07 05:41

Excuse my ignorance, but I ran into a problem that turned out to be challenging for my current knowledge in programming with Processing, even though the idea is quite simple

3条回答
  •  太阳男子
    2020-12-07 06:40

    Ringo has a solution that's perfectly fine.

    Another way you can do this easily is:

    bool addOnce = false;
    void draw()
    {
      int time = (millis() % 10000) / 1000;
      if (time == 9)
      {
          if(!addOnce) {
              addOnce = true;
              i++;
          }
      } else { addOnce = false; }
    }
    

    As long as time == 9, we'll only get through if(!addOnce) one time.

    After it changes, we reset the flag.

提交回复
热议问题