Scenes in Processing

Good afternoon, processing community, I would like to ask a question. How is it possible to implement “Scenes/Activities” on Processing?

Hello @OverLord

If I’m understanding your question correctly, the three threads below may be of interest:


1 Like

Thank you for the materials

1 Like

Your question is not very specific.

In the forum screens are often discussed as state (of a program)

here is another simple program

final int SPLASH    = 0;  // constants 
final int GAME      = 1; 
final int GAME_OVER = 2; 

int screen=SPLASH; 

void setup() {
  size(600, 600);

void draw() {

  switch(screen) {

  case SPLASH: 
    background (0); 
    float x=width/2; // =mouseX; 
    float y=height/2; // =mouseY; 

    vertex(x, y-80); // TOP
    vertex(x+40, y); // Right middle 
    vertex(x, y+80); // Bottom 
    vertex(x-40, y); // LEFT 

    text("Welcome to the game", 120, 120);


  case GAME:
    background (0);
    text("Game", 120, 120); 

  case GAME_OVER:
    background (0);
    text("You won", 220, 320); 

    background (0);
    text("unknown screen number", 220, 320);

void keyPressed() {

After screen++; you need an if to check if screen is > 2. If so, reset to 1.

Since draw() runs 60 times per second and we use switch(), only the lines of the current screen are executed.



Write a Base class „Scene“ with a method void draw(). Have one instance gscene pointing onto the current scene. Derive specific scenes from that class. Every draw call in processing now delegates to gscene.draw(). That‘s it. Jens

1 Like

Can you please show this as an example as I did?

1 Like

Objects are deleted or simply hidden??

When you have this at start of draw() you just don’t draw the object anymore

When you have a ArrayList of Object Bullets, it’s better to remove() them (when they are finished, after collision or after leaving the screen), so that you don’t have so many dead objects in your ArrayList.

  • But you need to provide more context so we can understand your question.
1 Like

I made the same scene system as you showed, everything works fine, thank you. Do the objects disappear when switching to a new scene. Let’s say I have scene 1 and scene 2 at my mom, I have background and objects on both scenes (squares, circles, etc), if I change scene to 2, what happens to the objects on scene 1
final int START = 1; //scene
final int GAME = 2; //scene
final int GAME_OVER = 3; //scene
int scene = START; //sceneCurrent

void settings (){
fullScreen (OPENGL);

void setup () {
scene = 1;

void draw() {
background (0);
switch(scene) { //смена сцены

case START: //1 activity
background (200)
ellipse(random (0, width), random (0, height), 70,70);
rect(random (0, width), random (0, height), 70,70);
scene = 2;
break; //end 1 atcivity

case GAME: //2 activity or scene 2
background (57,78,9);
break; //end 2 atcivity

case GAME_OVER: //3 activity

break; //end 3 activity

} // end switch
} //end draw