从图像中创建一个可单击的按钮

时间:2015-02-26 13:49:05

标签: button processing

我正在尝试在我的草图中实现一个按钮,到目前为止一直很好。保持简单我可以使用rects来做到这一点。但是,我想知道是否有办法加载图像并将其用作按钮的纹理,我的意思是,将图像作为按钮本身。我找不到任何地方如何做到这一点。

1 个答案:

答案 0 :(得分:1)

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

类似的东西:

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));
}
相关问题