But how do I get the coordinates of the rectangles I want to swap to redraw them in each other's previous positions? I have several rectangles that I want the user to be able to swap with each other.
Please don't start multiple threads for the same question. I'm deleting the other one, because you have answers here. But here's the code from over there
class Person{
int xinit;
int yinit;
String nom;
int xpos;
int ypos;
int xbut;
int ybut;
int count;
color borderColor;
Person (int iyinit,String inom,int iybut){
xinit=700;
yinit=iyinit;
nom=inom;
ypos=iyinit;
ybut=iybut;
count=0;
borderColor=#000000;
}
void mouseClicked(){
if (mouseX>=xinit && mouseX<=800){
count+=1;
if (count<=2){
borderColor=#ffff00;
}
if (count==2){
ypos=
count=0;
borderColor=#000000;
}
}
}
void draw(){
stroke(borderColor);
rect(xinit,ypos,100,50);
}
}
sorry, I thought it might be better to start a more precise thread and it says that asking help with code is for the other category. my bad, 1st time here
so, to clarify, I wanted to make a class for rectangles with names inside of them and I want the user to be able to click on the rectangles to swap them. I also tried to make it so that it "highlights" the chosen rectangles. The code is pretty incomplete for now. Also, I'm a bit new programming
Answers
when one has been clicked set a marker
isSwapped
to true inmousePressed()
:before
setup()
saydepending on isSwapped draw the rects in
draw()
as they are initially or in a new wayChrisir
But how do I get the coordinates of the rectangles I want to swap to redraw them in each other's previous positions? I have several rectangles that I want the user to be able to swap with each other.
it might help to show your entire code so that we know whet you mean
to swap two you mark first one rectangle and then the next??
Please don't start multiple threads for the same question. I'm deleting the other one, because you have answers here. But here's the code from over there
sorry, I thought it might be better to start a more precise thread and it says that asking help with code is for the other category. my bad, 1st time here
You can edit and change the category...
so, to clarify, I wanted to make a class for rectangles with names inside of them and I want the user to be able to click on the rectangles to swap them. I also tried to make it so that it "highlights" the chosen rectangles. The code is pretty incomplete for now. Also, I'm a bit new programming
Ah, didn't know that koogs, sorry!