Help for button class

edited October 2017 in Questions about Code

Hi there, unfortunately i have an issue also about to do a button class: i can't figure out how to obtain only one detection of "click", in my example i can't choose a color that rest so it generate a strobe effect when clicked. May i ask some help, for these apparently simple stuff? Thanks!

class Button {
  String label; // button label
  float x;      // top left corner x position
  float y;      // top left corner y position
  float w;      // width of button
  float h;      // height of button
  boolean state;
  boolean ready;
  boolean blink;

//boolean ready;
  // constructor
  Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
    label = labelB;
    x = xpos;
    y = ypos;
    w = widthB;
    h = heightB;
        blink = false;
    state = false;
    ready = true;
    //ready = true;

  void draw() {

    rect(x, y, w, h);
    textAlign(CENTER, CENTER);
    text(label, x + (w / 2), y + (h / 2));

    if (mousePressed){
    if ( ready && mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
      ready = false;
        state = !state;

       ready = true;

Button[] buttons = new Button[4];

int incr = 0;
int slot = 16;
void setup() {
  size(400, 400);

  buttons[1] = new Button("yo", 370, 10, 20, 20);


void draw() {


  //toggles[0].blink = ;



  • I whish to be able to add 1 to a variable each click

  • edited October 2017 Answer ✓

    Look at your code. What conditions must be true for the Button to have ready set to true? What conditions SHOULD it have?

    This is the same issue I solved for you the other day. Go back to yesterday's code and understand it better.

    Also, Ctrl + t auto-formats your code.

  • edited October 2017

    Thanks for support! i understand the question about ready for to be hit! But now i which to obtain a multitouch compatibility for android, i already read what there is about on the site, but i need a help to convert my classes, but i will open a post for it into android mode, Thanks!

Sign In or Register to comment.