Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
harkor
harkor's Profile
1
Posts
3
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
[Solved] Less code with mouseX and mouseY condition
[6 Replies]
31-Oct-2010 04:20 AM
Forum:
Programming Questions
Hello,
I'm a beginner in programming and I search a method for making a minimal code (a fonction?)
My code
// PERSO_0
if(mouseX <= 100 && mouseY <= 200){
imgPerso =loadImage(perso[0]);
image(imgPerso,0,0);
}
else if(mouseX <= 100 && mouseY <= 400){
imgPerso =loadImage(perso[0]);
imgPersoTitle =loadImage(persoTitle[0]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 100 && mouseY <= 600){
imgPerso =loadImage(perso[0]);
imgPersoTitle =loadImage(persoTitle[0]);
imgPersoFonction =loadImage(persoFonction[0]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_1
else if(mouseX <= 200 && mouseY <= 200){
imgPerso =loadImage(perso[1]);
image(imgPerso,0,0);
}
else if(mouseX <= 200 && mouseY <= 400){
imgPerso =loadImage(perso[1]);
imgPersoTitle =loadImage(persoTitle[1]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 200 && mouseY <= 600){
imgPerso =loadImage(perso[1]);
imgPersoTitle =loadImage(persoTitle[1]);
imgPersoFonction =loadImage(persoFonction[1]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_2
else if(mouseX <= 300 && mouseY <= 200){
imgPerso =loadImage(perso[2]);
image(imgPerso,0,0);
}
else if(mouseX <= 300 && mouseY <= 400){
imgPerso =loadImage(perso[2]);
imgPersoTitle =loadImage(persoTitle[2]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 300 && mouseY <= 600){
imgPerso =loadImage(perso[2]);
imgPersoTitle =loadImage(persoTitle[2]);
imgPersoFonction =loadImage(persoFonction[2]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
//PERSO_3
else if(mouseX <= 400 && mouseY <= 200){
imgPerso =loadImage(perso[3]);
image(imgPerso,0,0);
}
else if(mouseX <= 400 && mouseY <= 400){
imgPerso =loadImage(perso[3]);
imgPersoTitle =loadImage(persoTitle[3]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 400 && mouseY <= 600){
imgPerso =loadImage(perso[3]);
imgPersoTitle =loadImage(persoTitle[3]);
imgPersoFonction =loadImage(persoFonction[3]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_4
else if(mouseX <= 500 && mouseY <= 200){
imgPerso =loadImage(perso[4]);
image(imgPerso,0,0);
}
else if(mouseX <= 500 && mouseY <= 400){
imgPerso =loadImage(perso[4]);
imgPersoTitle =loadImage(persoTitle[4]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 500 && mouseY <= 600){
imgPerso =loadImage(perso[4]);
imgPersoTitle =loadImage(persoTitle[4]);
imgPersoFonction =loadImage(persoFonction[4]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_5
else if(mouseX <= 600 && mouseY <= 200){
imgPerso =loadImage(perso[5]);
image(imgPerso,0,0);
}
else if(mouseX <= 600 && mouseY <= 400){
imgPerso =loadImage(perso[5]);
imgPersoTitle =loadImage(persoTitle[5]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 600 && mouseY <= 600){
imgPerso =loadImage(perso[5]);
imgPersoTitle =loadImage(persoTitle[5]);
imgPersoFonction =loadImage(persoFonction[5]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_6
else if(mouseX <= 700 && mouseY <= 200){
imgPerso =loadImage(perso[6]);
image(imgPerso,0,0);
}
else if(mouseX <= 700 && mouseY <= 400){
imgPerso =loadImage(perso[6]);
imgPersoTitle =loadImage(persoTitle[6]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 700 && mouseY <= 600){
imgPerso =loadImage(perso[6]);
imgPersoTitle =loadImage(persoTitle[6]);
imgPersoFonction =loadImage(persoFonction[6]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_7
else if(mouseX <= 800 && mouseY <= 200){
imgPerso =loadImage(perso[7]);
image(imgPerso,0,0);
}
else if(mouseX <= 800 && mouseY <= 400){
imgPerso =loadImage(perso[7]);
imgPersoTitle =loadImage(persoTitle[7]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 800 && mouseY <= 600){
imgPerso =loadImage(perso[7]);
imgPersoTitle =loadImage(persoTitle[7]);
imgPersoFonction =loadImage(persoFonction[7]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_8
else if(mouseX <= 900 && mouseY <= 200){
imgPerso =loadImage(perso[8]);
image(imgPerso,0,0);
}
else if(mouseX <= 900 && mouseY <= 400){
imgPerso =loadImage(perso[8]);
imgPersoTitle =loadImage(persoTitle[8]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 900 && mouseY <= 600){
imgPerso =loadImage(perso[8]);
imgPersoTitle =loadImage(persoTitle[8]);
imgPersoFonction =loadImage(persoFonction[8]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
// PERSO_9
else if(mouseX <= 1000 && mouseY <= 200){
imgPerso =loadImage(perso[9]);
image(imgPerso,0,0);
}
else if(mouseX <= 1000 && mouseY <= 400){
imgPerso =loadImage(perso[9]);
imgPersoTitle =loadImage(persoTitle[9]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
}
else if(mouseX <= 1000 && mouseY <= 600){
imgPerso =loadImage(perso[9]);
imgPersoTitle =loadImage(persoTitle[9]);
imgPersoFonction =loadImage(persoFonction[9]);
image(imgPerso,0,0);
image(imgPersoTitle,0,0);
image(imgPersoFonction,0,300);
}
In reality, I have 50 perso and this code is very long.
Do you have solutions?
Excuse me for my English, my basis language isn't English.
«Prev
Next »
Moderate user : harkor
Forum