We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I get a error that dispays "it looks like you're mixing active and static modes" on Button(float xPos, float yPos, float w, float h, color onColor, color offColor).. How do I fix this?
Button(float xPos, float yPos, float w, float h, color onColor, color offColor)
{
x= xPos;
y= yPos;
this.w= w;
this.h= h;
this.onColor= onColor;
this.offColor= offColor;
this.isPressed= false;
}
boolean hitTest(float mx, float my)
{
if (mx> x && mx< x + w && my> y && my< y + h)
{
return true;
}
return false;
}
void drawButton ()
{
if(isPressed)
{
fill(onColor);
}
else
{
fill(offColor);
}
rect(x,y,w,h);
}
Button josh;
Button sam;
void setup()
{
size(1000, 1000);
josh= new Button(200,200,50,50,color(0,255,0),color(255,0,0));
sam= new Button(200,400,50,50,color(0,255,0),color(255,0,0));
}
Answers
It looks like Button is meant to be a class
But you are missing
class Button {
and then before Button josh the }
also missing the vars like x y w h ..... in the class
Look at reference : class
And read the tutorial on objects / oop
Did you copy the code maybe and forgot the beginning?
yeah, here's the entire code
please go back, edit your post
and format the code correctly
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text#latest
You need to add the
setup()
method so you are not in immediate mode.so, does it work now?
some minor errors:
this
must be
Class small : class
no ()
no
}
here but AFTER the entire functiondrawButton ()
explanation
understand that a class is a package where you have
some errors in mouseClicked()
e.g.
the last line:
delete this line please.
Chrisir ;-)
@quark: he has setup()
other errors
His setup appears to be INSIDE the Button class :)
Just formatted his code - setup, draw, mouseclicked etc are in his Button class :)
yes
They shouldn't be :D
true, but the } in line 26 is also wrong....
I did everything that y'all advised me to do and it fixed all errors but I also don't have any buttons, just a gray screen..
please go back, edit your post
and format the code correctly
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text#latest
still one too many } at the very end
one missing } before Button josh;
I edited it. Is the formatting still wrong?
It works now!! Thank you!!!
this should be
sam
, tooyou're welcome
Yeah, I caught that and fixed it
;-)