Please help my Processing code. due to tomorrow!

I want to make program that press the button on the first screen to play the first video, and when I press key ‘s’ or ‘l’ on the screen, I want to make them show different videos, but it’s too hard because I haven’t learned it yet.

import processing.video.*;
Movie myMovie;
Movie myMovie2;
Movie myMovie3;
int caseNum = 1;
Boolean btn1 = false;
Boolean btn2 = false;

void setup() {
  size(800, 600);
  myMovie = new Movie(this, "Movie01B.mp4");
  myMovie.play();
}

void draw() {
  image(myMovie, 0, 0);
  rect(90, 490, 35, 35, 7);
  fill(255);
  textSize(23);
  text("Start", 150, 515);
  if (mouseX>125 && mouseX<90 && mouseY>525 && mouseY<490) {
    btn1=true;
  } else {
    btn1=false;
  }
  
  switch(caseNum) {
  case 1:
   //fullScreen();
   image(myMovie, 0, 0);
   myMovie = new Movie(this, "Movie01B.mp4");
   myMovie.play();
   
  case 2:
   //fullScreen();
   image(myMovie2, 0, 0);
   myMovie2 = new Movie(this,"Movie02B.mp4");
   myMovie2.play();
   rect(90, 490, 35, 35, 7);
   fill(255);
   textSize(23);
   text("Play again", 150, 515);
   if (mouseX>125 && mouseX<90 && mouseY>525 && mouseY<490) {
     btn2=true;
   } else {
     btn2=false;
   }
   
  case 3:
    //fullScreen();
    image(myMovie3, 0, 0);
    myMovie3 = new Movie(this, "Movie03B.mp4");
    myMovie3.play();
  }
}

void keyPressed () {
  switch(caseNum) {
    case 1:
      if (key == 's') {
        caseNum = 2;
      }
      
    case 2:
      if (key == 'l') {
        caseNum = 3;
      }
       break;
  }
}

void mousePressed () {
  switch(caseNum) {
    case 1:
      if (btn1) {
        caseNum = 1;
      }
      break;
      
      case 2:
        if (btn2) {
          caseNum = 1;
        }
        break;
  }
}
  

void movieEvent(Movie m) {
  m.read();
}

please help! due to tomorrow…:frowning: :frowning:

1 Like

Welcome to the forum!

you are almost there!

  • Load all movies in setup, nowhere else
  • caseNum tells you which movie to show
  • So instead of saying image(myMovie, 0, 0); at the start of draw(), so should use switch(caseNum) which you already have. Use it.
  • start draw() with background(0);
  • in mousePressed () is an error: caseNum = 1; occurs twice; one should be caseNum = 2;
  • don’t use this myMovie.play(); in draw; I thik it restarts the video. Instead, use it where you change/start a video, in mousePressed or keyPressed.
  • In the switch statements, you need to have break; after each case block!
    so this
 switch(caseNum) {
  case 1:
    if (key == 's') {
      caseNum = 2;
    }

  case 2:

must be

 switch(caseNum) {
  case 1:
    if (key == 's') {
      caseNum = 2;
    }
    break;

  case 2:
  • Same in every switch block for every case
  • When you don’t want the movie to start immediately, don’t say myMovie.play(); in setup.
2 Likes

this is a bit off.

Let’s write it like this:

if (mouseX>125 && 
    mouseX<90 && 
    mouseY>525 && 
    mouseY<490) {

or with a better order of the numbers:

if (mouseX<90 && 
    mouseX>125 && 
    mouseY<490 && 
    mouseY>525) {

Now we have the smaller number first (for mouseX, then for mouseY).

BUT:
If mouseX is bigger than 125, it can’t be smaller than 90 at the same time.
Same with mouseY.

So you mixed up > and < maybe?

3 Likes

Your post has been edited to format the code for better readability. Please review our FAQ or refer to the animation below for guidance on posting code. Thank you!

ezgif.com-gif-maker (1)

Sorry, it was an old thread that popped up somehow.

1 Like

This answers the somehow:

It moved to the top of the list after the edit.

Wonder if it was submitted by the deadline?

:)

1 Like

Thank you for our answer!

Chrisir

1 Like