Change scenarios with loop

0

How do I create a loop in Processing that switches between three or more scenarios (summer, winter and fall) when my object (car) reaches the edge of the window?

    
asked by anonymous 19.10.2017 / 00:13

1 answer

4

A way of doing, not very beautiful but that works:

  • In variable declarations include:

    int season = 0; // 0=summer, 1=fall, 2=winter 
    
  • Create this new method:

    void changeSeason() {
        // Gira o índice da estação atual
        if(++season > 2) season = 0;
    
        // Desenha o cenário correspondente
        if(season === 0) {
            scenarioSummer();
        } else if(season === 1) {
            scenarioFall();
        } else if(season === 2) {
            scenarioWinter();
        }
    }
    
  • And the draw method would look like this:

    void draw() {
        timeFrame = frameCount % width;
    
        // Se chegou no fim da tela
        if(timeFrame === 0) {
            changeSeason(); 
        }
    }
    
  • 20.10.2017 / 21:18