0

我正在处理一个简单的翻转。目前,当我将鼠标悬停在椭圆上时,翻转有效,但当我将鼠标移动到另一个位置时它不会消失。

float x = random(0, 255);
float y = random(0, 255);
float d;
float radius;
boolean rollover = false;

void setup() {
  PFont font = loadFont("DialogInput-12.vlw");
  size (800, 600);
  noStroke();
  smooth();
}

void draw() {
  drawData(x, y);

  if (rollover) {
  fill(y);
  textAlign(CENTER);
  text("hahaha", width/2, height/2);
  }

}

void drawData(float x, float y) {

  float value = x;
  float d = dist(x, y, mouseX, mouseY);
  float radius = map(value, 0, y, 10, 10);
  fill(x);  
  ellipse(x, y, radius, radius);

  if(d < radius) {
  rollover = true;
  } else {
    rollover = false;
  }


}
4

1 回答 1

4

只需在绘制循环的开头添加一个“背景(颜色值)”行:

float x = random(0, 255);
float y = random(0, 255);
float d;
float radius;
boolean rollover = false;

void setup() {
  PFont font = loadFont("DialogInput-12.vlw");
  size (800, 600);
  noStroke();
  smooth();
}

void draw() {
  background(255);  // add this

  drawData(x, y);

  if (rollover) {
  fill(y);
  textAlign(CENTER);
  text("hahaha", width/2, height/2);
  }

}

void drawData(float x, float y) {

  float value = x;
  float d = dist(x, y, mouseX, mouseY);
  float radius = map(value, 0, y, 10, 10);
  fill(x);  
  ellipse(x, y, radius, radius);

  if(d < radius) {
  rollover = true;
  } else {
    rollover = false;
  }


}
于 2013-01-19T00:56:19.523 回答