因此,我從一週前開始學習處理,並試圖讓點擊移動的橢圓。我遵循處理API,但我無法弄清楚。我刪除了所有與可點擊的橢圓相關的代碼,因爲它是一團糟。如何使(移動)橢圓點擊?處理
在部分,在那裏我宣佈我的所有增值經銷商可以我用看到:
int breedte = 600;
int hoogte = 600;
這些假設是:
int breedte = width;
int hoogte = height;
但由於某種原因,寬度和高度不要輸出的寬度和高度爲:
size(600,600)
那麼,我要問的是:
我怎樣才能讓(移動)橢圓點擊?
爲什麼我不能在'int hoogte'和'int breedte'上使用寬度和高度?
感謝advace。
主文件:
int x = 0;
int leftSide = 0;
int rightSide = width;
int bottomSide = height;
int totalHits = 0;
int totalMiss = 0;
boolean start = false;
int circelSize = 100;
int circelRings = 24;
int circelSpeed = 1;
int circelPositionY = 0;
int breedte = 600;
int hoogte = 600;
String[] buttonText = {"Start","Stop"};
String buttonTextActive = buttonText[0];
int[] buttonColor = {0,90};
int buttonColorActive = buttonColor[0];
int buttonHighlight = 50;
int buttonSize = 80;
int buttonY = breedte - (buttonSize /2);
int buttonX = hoogte/2 - 40;
void setup() {
size(600, 600);
smooth();
noStroke();
}
void draw() {
if (start) {
circelPositionY = circelPositionY + circelSpeed;
drawCircel(circelPositionY);
if (circelPositionY == (width + circelSize)) {
circelPositionY = 0;
}
}
drawButton();
}
活動文件:
void mousePressed() {
// Start or Stop button
if(mouseX > buttonX & mouseX < buttonX + buttonSize & mouseY > buttonY & mouseY < buttonY + (buttonSize/2)){
if(start) {
start = false;
buttonColorActive = buttonColor[0];
buttonTextActive = buttonText[0];
println("Game stoped");
} else {
start = true;
buttonColorActive = buttonColor[1];
buttonTextActive = buttonText[1];
println("Game started");
}
}
//HERE SHOULD GO THE CLICKABLE ELLPISE
}
功能文件:
void drawCircel(int circelPositionY) {
background(204);
for (int i = 0; i < circelRings; i = i+1) {
int even = i % 2;
if (even == 0) {
fill(255,0,0);
ellipse(-(circelSize/2) + circelPositionY, height/2 - (circelSize/2), circelSize - (i * (circelSize/circelRings)), circelSize - (i * (circelSize/circelRings)));
} else {
fill(255);
ellipse(-(circelSize/2) + circelPositionY, height/2 - (circelSize/2), circelSize - (i * (circelSize/circelRings)), circelSize - (i * (circelSize/circelRings)));
}
}
}
void drawButton() {
fill(buttonColorActive);
rect(buttonX,buttonY, buttonSize, buttonSize/2);
fill(255);
textAlign(CENTER, CENTER);
text(buttonTextActive, buttonX + (buttonSize/2),buttonY + (buttonSize/4));
}
嗨凱文,今天你是我的英雄。你的答案不能更清楚!自我推銷也正是我想要添加到我的項目中的,而不是對你的羞恥;)。我已經閱讀了MCVE,我的下一篇文章會更好。 謝謝我的朋友 –