Hi, i’m trying to draw a button as an exercise, with hover effect, this button i’m doing have a dot close to each corner of the button, on the outside and this dot is supposed to animate entering the button, the problem is it only increment one time, i’ve tested only this animation in another sketch without writing in a class, just in the draw function and it worked just fine. i’ve tried using a for loop as well, but i got a grey screen.
The question is, how do animate something using the incrementing variable within the class?
This is my code
Button b = new Button();
PFont space;
void setup () {
size(700, 700);
space = createFont("SpaceGrotesk-Medium.ttf", 72);
}
void draw () {
background(0);
b.display("ENVIAR", 50, 50, 72);
}
class Button {
void display(String buttonTitle, int x, int y, int t) {
int dot = 3;
int paddingLR = 20;
int paddingTB = t/2;
int w = (int)textWidth(buttonTitle)+paddingLR*2;
int h = t+paddingTB*2;
//mL stands for margin Left, so the others are margin Top, Right, Bottom.
int mL = x-10;
int mT = y-10;
int mR = x+w+10;
int mB = x+h+10;
color mainColor = color(#85D89C);
color hoverColor = color(#6CB27F);
color bttnColor = mainColor;
if (mouseX>x && mouseX<w && mouseY>y && mouseY<h) {
bttnColor = hoverColor;
mL++;
mT++;
mR--;
mB--;
} else {
bttnColor = mainColor;
mL--;
mT--;
mR++;
mB++;
}
stroke(255);
strokeWeight(2);
fill (bttnColor);
rect(x, y, w, h);
noStroke();
fill(#FFFFFF);
rect(mL, mT, dot, dot);
rect(mR, mT, dot, dot);
rect(mR, mB, dot, dot);
rect(mL, mB, dot, dot);
textFont(space);
textSize(t);
textAlign(LEFT, CENTER);
text(buttonTitle, x+paddingLR, y+paddingTB+t/3);
}
}
Thank you for your attention!