Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : how do you put a counter on any array?

$
0
0
 I think the problem is at line " myMoviesIndex = 0;" and also the chain of testing is a bit confused ... well an example says more than a thousand words :) I'm not testing if some one is there as mouse can't be pressed by some ghost, maybe a robot, but not a ghost... so i called  nextMovie straight form mousePressed.

  1. import processing.video.*;

  2. int maxmyMovies=3;  //total # movies
  3. int myMoviesIndex=0;  //initial movie to be displayed

  4. Movie[] myMovies = new Movie[maxmyMovies] ; //declare array of movies

  5. boolean movieDone = false;


  6. void setup( ) {

  7.   size(1280, 720); 
  8.   for (int i=0; i<myMovies.length; i++) {
  9.     myMovies[i] = new Movie(this, "comedy"+nf(i, 2)+".mov");  //loading movies into the array
  10.   }
  11.   myMovies[myMoviesIndex].loop(); //play the first movie
  12. }
  13. void draw() {
  14.   image(myMovies[myMoviesIndex], 0, 0, 1280, 720);   //display one movie

  15.   if (myMovies[myMoviesIndex].time() >= myMovies[myMoviesIndex].duration()) {
  16.     // the current movie is done


  17.     myMovies[myMoviesIndex].stop(); // stop the current movie 
  18.     movieDone = true;
  19.   }



  20.   fill(255);
  21.   text(myMovies[myMoviesIndex].time(), 30, 30); 
  22.   text(myMovies[myMoviesIndex].duration(), 30, 60);
  23. }


  24. void movieEvent(Movie myMovies) {
  25.   myMovies.read();  //read new frames from movie
  26. }


  27. void mousePressed() { 

  28.   if(movieDone){
  29.   nextMovie();
  30.   movieDone = false;
  31.   }
  32. }

  33. void nextMovie() {
  34.   myMovies[myMoviesIndex].stop(); // stop the current movie
  35.   myMoviesIndex=(myMoviesIndex+1) % myMovies.length;  //increment movie by one and return to zero once size of array is reached
  36.   myMovies[myMoviesIndex].play(); // play the next movie
  37. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles