We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there :) What I'm trying to do: I have an array of PImages that are supposed to first disappear when being clicked and then the next PImage of that array is supposed to appear on a random position. Also, I'm not using the actual cursor but an image of a cursor that moved in opposite directions. So, if the actual cursor is going left, the fake on is going right, and so on.
To start of I made this, which actually works. Here I'm just using a rectangle instead of the PImages.
float posX = 0;
float posY = 0;
float rectW = 100;
float rectH = 100;
PImage cursor;
void setup(){
size(800,600);
noCursor();
cursor = loadImage("cursor.png");
}
void draw(){
background(255);
cursor.resize(16,0);
rect(posX, posY, rectW, rectH);
image(cursor, width-mouseX, height-mouseY);
}
void mousePressed(){
if(width-mouseX > posX && width-mouseX < (posX + rectW) && height-mouseY > posY && height-mouseY < (posY + rectH)){
posX = random(0, width-rectW);
posY = random(0, height-rectH);
}
}
But when replacing the rectangle with the array PImage, is doesn't work anymore and I can't seem to make it work, I've been trying for days.
float posX = 0;
float posY = 0;
float insultW = 100;
float insultH = 100;
PImage cursor;
PImage[] insults;
int index = 0;
void setup(){
size(800,600);
noCursor();
insults = new PImage[6];
for(int i = 0; i < insults.length; i++){
insults[insults.length-1 -i] = loadImage("insult_"+i+".jpg");
}
cursor = loadImage("cursor.png");
}
void draw(){
background(255);
//rect(posX, posY, rectW, rectH);
image(insults[index], posX, posY);
image(cursor, width-mouseX, height-mouseY, insultW, insultH);
cursor.resize(16,0);
}
void mouseClicked(){
if(width-mouseX > posX && width-mouseX < (posX + insultW) && height-mouseY > posY && height-mouseY < (posY + insultH)){
posX = random(0, width-insultW);
posY = random(0, height-insultH);
index++;
if(index>=6){
index = 0;
}
}
}
Please help me.