Change scenarios with loop

Asked

Viewed 78 times

0

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

  • This is from Unity?

  • No, the language is Processing. But an example in Java, would help me a lot.

  • 1

    You can show the code of one of the functions scenarioXXXXX? The ideal solution would be for you to have an array of scenarios, but to propose this we would need to know more about what happens in these functions.

  • I put all the code that makes more sense to understand the problem.

1 answer

4


A way to do it, not very pretty but it works:

  1. In variable declarations include:

    int season = 0; // 0=summer, 1=fall, 2=winter 
    
  2. 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();
        }
    }
    
  3. And the method draw would look like this:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.