Hi,
I'm having difficulties figuring out why the following piece of code doesn't do what I want it to do.
I have a list of images 'face[]', and mouse input determins which of those images to draw. When the 'curFace' changes I want to copy a section of 'face[curFace]' to another image, 'mouthImg', which for reasons of testing is also drawn - half size - in the lower right of the scene.
The problem is that 'mouthImg' doesn't update each time the curFace changes. Only in the first loop the copy is succesful and for the rest of the time 'mouthImg' stays the same.
I feel I am missing some obvious error in the code, so I hope someone can help see clearer.. or teach me things I did not know about copy();..
thanks
/prinds
link to example applet
http://prinds.com/img_copy_test Code:
PImage[] face;
int numFaces = 15;
PImage mouthImg = new PImage(225, 75);
int curFace = 0;
int lastFace = -1;
void setup(){
size(320,240);
face = new PImage[numFaces];
for(int i=0; i<numFaces; i++ ){
face[i] = loadImage("face/smile" + nf(i+1,4) + ".gif");
}
}
void draw(){
curFace = 15*mouseX/width;
if(curFace!=lastFace){ //if curFace has changed, copy the mouth of the new face into mouthImg
mouthImg.copy(face[curFace], 50,150, 225,75, 0,0, 225,75);
lastFace=curFace;
}
image(face[curFace],0,0,width,height);
image(mouthImg, 200,200, 225/2,75/2);
noFill();
stroke(255,0,0);
rect( 200,200, 225/2,75/2);
}