从图像制作可点击的按钮

Make a clickable button from an image

我正在尝试在我的草图中实现几个按钮,到目前为止一切顺利。为简单起见,我可以使用 rects 来做到这一点。但是,我想知道是否有一种方法可以加载图像并将其用作按钮的纹理,我的意思是,使图像成为按钮 itself.I 在任何地方都找不到如何做到这一点。

只需使用与图像坐标矩形相同的逻辑...

类似于:

PImage button;
int bX = 150, bY = 150;
color c = randomColor();

void setup(){
  size (400,400);
  button = loadImage("http://dressitupembellishments.com/images/bulk_buttons/button/green_button.jpg");
  button.resize(100,0);
}
void draw(){
  background(c);
  image(button, bX, bY);
}


void mouseClicked(){
  if( mouseX > bX && mouseX < (bX + button.width) &&
      mouseY > bY && mouseY < (bY + button.height)){
        c = randomColor();
      };
    }

color randomColor(){
  return color(random(255), random(255), random(255));
}