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

前端 未结 3 1459
日久生厌
日久生厌 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:14

    You could store the last number of seconds in a static (or global) variable, and only increment i when the current number of seconds is higher than the oldsecs

    void draw() {
        static int oldsecs = 0;
        int secs = millis() / 1000;
        if (secs > oldsecs) {
            i++;
            oldsecs = secs;
        }
        ...
    

    Assuming the language is C, and the int type is not overflowed by the number of seconds.

提交回复
热议问题