We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Folks,
Please Can you help me find the problem on my code
What I want is when the user move the mouse over the the wheel of the car, start the erase effect I mean the picture in the foreground disappear and the movie in thr forground appear. Like the picture below))
The problem tha is happening is: -The movie triggered by the mouse over is starting anywhere - When I pas the mouse over the whel the movie(triggered by the the mouse over start to loop each time I move the mouse)
Below is my code
import processing.video.*;
Movie myMovie;
static final int DIAM = 0100, FPS = 10;
PImage bgMask;
PImage img;
PImage img2;
int x = 628;
int y =595;
int w = 50;
int h = 50;
void setup() {
size(1600, 1067, JAVA2D);
frameRate(FPS);
smooth(4);
imageMode(CORNER);
myMovie = new Movie(this, "better.mp4");
bgMask = loadImage("laDefense2.jpg");
}
void draw() {
// Replace background() w/ your video feed:
//background((color) #00FFFF);
image(myMovie, 0, 0);
myMovie.loop();
//img = loadImage("laDefense.jpg");
//image(img, 0, 0);
// bgMask is the foreground overlay mask:
image(bgMask, 0, 0);
}
void mouseMoved() {
// Alpha 0 is 100% transparent.
// Alpha 0xFF 100% opaque:
alphaRect(bgMask, mouseButton == LEFT? 0 : 0, DIAM);
}
void alphaRect(PImage img, color a, int dim) {
dim >>= 1; // diameter to radius.
a <<= 030; // move alpha channel to its right octet.
final color[] p = img.pixels;
final int w = img.width, h = img.height;
final int minX = max(mouseX - dim, 0);
final int maxX = min(mouseX + dim, w);
final int minY = max(mouseY - dim, 0);
final int maxY = min(mouseY + dim, h);
//If click determin region
{
if (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h) {
myMovie = new Movie(this, "better.mp4");
myMovie.play();
} else {
print("outiside rect");
}
}
for (int row = minY; row != maxY;)
for (int col = minX, rw = w*row++; col != maxX;) {
final int idx = rw + col++;
p[idx] = p[idx] & 0xFFFFFF | a;
}
img.updatePixels();
}
void movieEvent(Movie m) {
m.read();
Answers
I know little about video in Processing, but one thing is obvious: you should not load a movie on a mouse event, even more one called as often as mouseMoved()! You load the movie in setup(), it is enough.
Moreover, calling play() each time the mouse moves inside the rect is ineffective, it should be called only once, the first time the mouse is detected inside the rect. Have a global boolean, eg. call it isPlaying. Set it to true on first positive test of mouse in rect, and play the movie. If then test if it is true, to avoid playing again.
Something like:
Also, take a look in the thread below for further tips on using a
boolean
flag for Movie playing:http://forum.processing.org/two/discussion/5043/how-to-display-a-blank-frame-when-a-video-is-paused