UFO(本質的には灰色の楕円)が画面中央から表示され、エッジまで飛んでいくプログラムを書いています。マウスを押すと表示されるレーザーがあり、マウスが離されると消えます。マウスをクリックするとUFOが消える/レーザーが触れるようにしたい。 私はUFOクラスを作成し、その動きとスピードを決定する変数を作成し、レーザーをカーソルに直接表示させることができました。カーソルがUFOの半径(または直径)内にあるかどうかをチェックし、それをUFOのために作成したforループの内側に配置するためのif文を作成することを考えました。しかし、私はそれを実現させるための正しい構文をどのように達成するかについてはわかりません。 注:スケッチを再生した後、最初の円が表示されるまで数秒待つ必要があります。クリックして移動円を消す処理
UFO[] ufos = new UFO[3];
void setup() {
size(700, 700);
for (int j = 0; j < ufos.length; j++) {
ufos[j] = new UFO();
}
}
//UFO class
//Class setup ends on line 61
class UFO {
float a;
float b;
float c;
float sa;
float sb;
float d;
UFO() {
//declare float a/b/c value
a = random(-width/2, width/2);
b = random(-height/2, width/2);
c = random(width);
}
//UFO movement
void update() {
//float c will serve as a speed determinant of UFOs
c = c - 1;
if (c < 5) {
c = width;
}
}
//UFO setup
void show() {
//moving x/y coordinates of UFO
float sa = map(a/c, 0, 1, 0, width);
float sb = map(b/c, 0, 1, 0, height);
float d = map(c, 0, width, 50, 0);
//UFO drawing shapes
//ellipse is always sa (or sb)/c to allow UFO to appear
//as if it is moving through space
fill(200);
ellipse((sa/c), (sb/c), d + 5, d+5);
//Hides UFO way off the screen
//and replaces it with a black-filled ellipse until
//it forms into a full circle
//When radius d becomes 50, the UFO flies from the
//center of the screen to off of the screen
if (d < 50) {
fill(0);
ellipse(-5, -10, 90, 90);
sa = 10000;
sb = 10000;
}
}
}
void draw() {
//Background
background(0);
//Translated the screen so that the UFOs appear to fly from
//the center of the screen
translate(width/2, height/2);
//UFO draw loop, make UFO visible on screen
for (int j = 0; j < ufos.length; j++) {
ufos[j].update();
ufos[j].show();
//mouse-click laser
if (mousePressed == true) {
fill(200,0,0);
ellipse(mouseX - 352,mouseY - 347,50,50);
}
}
}
クロスポストをリンクしてください:http://forum.happycoding.io/t/make-a-moving-circle-disappear-when-clicked-on/47 そして、私が答えたところで質問を削除したようですこれはすでにStack Overflowにあります。その質問はどこに行きましたか? –