inversion of ypos
in
Programming Questions
•
7 months ago
Hello ,
i'm trying to make these buttons wich turn red when ever the mouse goes over them.
i wanted it to be possible to make as much buttons as needed , so i decided to try it whit a class and objects.
i did succeed in the making of the buttons but my colour code gets inverted.
i don't know what i did wrong, the recognision of the presence of the mouse in each rect is verry important for the future of this project.
I would be so verry gratefull if you could help me out,
here is my code:
- Boutton B1 = new Boutton (5,5);
- Boutton B2 = new Boutton (5,60);
- boolean INSIDE;
- void setup(){
- int L = displayWidth-((displayWidth/100)*10);
- int l = displayHeight-((displayHeight/100)*10);
- size (L,l);
- background (0);
- }
- void draw(){
- B1.affi();
- B1.ext();
- B2.affi();
- B2.ext();
- }
- class Boutton {
- float ypos,xpos;
- Boutton (float x , float y){
- ypos = y;
- xpos = x;
- }
- void affi(){
- if (INSIDE == true) fill (255,0,0);
- else fill(255);
- rectMode(CORNER);
- if( mouseX > xpos && mouseX < xpos+200 && mouseY > ypos && mouseY < ypos + 50 ){
- INSIDE = true;
- }
- else{
- INSIDE = false;
- }
- }
- void ext(){
- rect ( xpos ,ypos ,200,50);
- }
- }
1