Loading different scenes after time delay

please format code with </> button * homework policy * asking questions

So when the code begins to run (play), I want an image to fill the screen. After a time delay, let’s say 5 seconds, I want to load a different scene as in

int sceneNum = 1

If sceneNum == 1 void scene1(){}

Hi,

Welcome to the community! :wink:

For tracking the time, you can check those functions in the Processing documentation :

This is a more complex example (but very modular if you want to add scenes) :

ScenePlayer scenePlayer;

void setup(){
  size(500, 500);
  
  // Initialize the scene player
  // With 5000 milliseconds (5 seconds between each scenes)
  scenePlayer = new ScenePlayer(5000);
  
  // Add some scenes
  scenePlayer.addScene(new BlackScene());
  scenePlayer.addScene(new RedScene());
}

void draw(){
  scenePlayer.update();
  scenePlayer.draw();
}

// The ScenePlayer class is holding all the scenes
class ScenePlayer{
  int currentScene;
  ArrayList<Scene> scenes;
  boolean isPlaying = false;
  int slideTime;
  int currentTime;
  
  ScenePlayer(int slideTime){
    scenes = new ArrayList<Scene>();
    this.slideTime = slideTime;
    
    // Initialize the time
    currentTime = millis();
  }
  
  // Add a new scene
  void addScene(Scene scene){
    scenes.add(scene);
  }
  
  void update(){
    // If the delay has ended
    if(millis() - currentTime > slideTime){
      // Move to the next scene
      nextScene();
      // Reset the time
      currentTime = millis();
    }
  }
  
  // Dispay the curren scene
  void draw(){
    scenes.get(currentScene).draw();
    
    // Display the scene counter and the time
    fill(255);
    textSize(20);
    text("Scene n°" + currentScene, 50, 50);
    
    int timeLeft = floor((slideTime - (millis() - currentTime)) / 1000) + 1;
    text("Time left : " + timeLeft + " seconds", 250, 50);
  }
  
  // Move to the next scene
  void nextScene(){
    currentScene = (currentScene + 1) % scenes.size();
  }
}

// The interface is representing a scene
// Each scene has it's own draw() method
interface Scene{
  void draw();
}

// SCENES -------------------------------------

class BlackScene implements Scene{
  void draw(){
    // Black background
    background(0);
  }
}

class RedScene implements Scene{
  void draw(){
    // Red background
    background(255, 0, 0);
  }
}

It’s using the following notions :

If you have any questions, let me know!