Cannot use a .move function on Pimage
in
Programming Questions
•
1 years ago
I am making a program to make it so that on mousePressed, a random image comes onto the screen in a random location. I have achieved this, now I am interested in getting the images, once displayed on the screen to move according to the mouse location.
I got that code from the processing example of objects, and incorporated an array of objects.
The problem I am having is that the error message is telling me that I cannot invoke (int, float) on an array type Pimage. I'm not really sure if what I'm doing is possible, but I thought i would put it out there to see if anyone had an idea.
here is my code (with the mousePressed portion out)
PImage[] imageArray = new PImage[4];
void setup()
{
size(800, 800);
fill(255, 204);
noStroke();
background(255);
imageArray [0] = loadImage("p0.gif");
imageArray [1] = loadImage("p1.gif");
imageArray [2] = loadImage("p2.gif");
imageArray [3] = loadImage("p3.gif");
}
/*
// void mousePressed(){
image(imageArray[(int)random(4)], mouseX, mouseY);
image(imageArray[(int)random(4)],(mouseX+(width*0.05))%width, mouseY+(height*0.025));
image(imageArray[(int)random(4)],mouseX/4, mouseY-(height*0.025));
image(imageArray[(int)random(4)],mouseX-(width/2), (height-mouseY));
} */
void draw()
{
imageArray.move(mouseX-(width/2), mouseY+(height*0.1));
imageArray[1].move((mouseX+(width*0.05))%width, mouseY+(height*0.025), 20);
imageArray[2].move(mouseX/4, mouseY-(height*0.025), 40);
imageArray[3].move(mouseX-(width/2), (height-mouseY), 50);
}
void move (float posX, float posY, float damping) {
float dif = ypos - posY;
if (abs(dif) > 1) {
ypos -= dif/damping;
}
dif = xpos - posX;
if (abs(dif) > 1) {
xpos -= dif/damping;
}
}
void display() {
for (int i=0; i<t; i++) {
rect(xpos+(i*(d+w)), ypos, w, height*h);
}
}
1