按钮在 Processing 4 beta 1 中不起作用
Button not working in Processing 4 beta 1
我只是无法让我的代码工作。它使按钮,但它不工作。那你能帮我吗?
它使文本正常显示,按钮也出现了。但它不起作用,我也尝试过使用不同的功能,如 background(10)
等
Button login1;
boolean clicked = false;
void setup() {
fullScreen();
loginPage();
}
void draw() {
if (login1.isClicked()) {
print("AAAA");
}
login1.update();
login1.render();
}
void loginPage() {
background(27, 50, 131);
textSize(70);
fill(255);
text("System Statku Organizacji 587 'Aurora'", 600, 150);
login1 = new Button(100,50,400,200,"Zaloguj sie",64, 136, 253,255,255,255);
}
class Button {
boolean Pressed = false;
boolean Clicked = false;
PVector Pos = new PVector(0,0);
float Width;
float Height;
color Colour;
color textColour;
String Text;
Button(int x, int y, float w, float h, String t, int r, int g, int b, int tr, int tg, int tb) {
Pos.x = x;
Pos.y = y;
Width = w;
Height = h;
Text = t;
Colour = color(r,g,b);
textColour = color(tr,tg,tb);
}
void update() {
if (mousePressed == true && mouseButton == LEFT && Pressed == false) {
Pressed = true;
if (mouseX >= Pos.x && mouseX <= Pos.x+Width && mouseY >= Pos.y && mouseY <= Pos.y+Height) {
}
} else {
Clicked = false;
Pressed = false;
}
}
void render() {
noStroke();
fill(Colour);
rect(Pos.x,Pos.y,Width,Height);
fill(textColour);
textAlign(CENTER,CENTER);
text(Text,Pos.x+(Width/2),Pos.y+(Height/2));
}
boolean isClicked() {
return(Clicked);
}
}
将此添加到代码底部(在按钮 class 下方)。我不确定您是否真的需要 Pressed 和 Clicked 布尔值。
void mousePressed(){
if((mouseX >= login1.Pos.x) && (mouseX <= login1.Pos.x + login1.Width) && (mouseY >= login1.Pos.y) && (mouseY <= login1.Pos.y + login1.Height)){
println("You hit the login button.");
}
}
我只是无法让我的代码工作。它使按钮,但它不工作。那你能帮我吗?
它使文本正常显示,按钮也出现了。但它不起作用,我也尝试过使用不同的功能,如 background(10)
等
Button login1;
boolean clicked = false;
void setup() {
fullScreen();
loginPage();
}
void draw() {
if (login1.isClicked()) {
print("AAAA");
}
login1.update();
login1.render();
}
void loginPage() {
background(27, 50, 131);
textSize(70);
fill(255);
text("System Statku Organizacji 587 'Aurora'", 600, 150);
login1 = new Button(100,50,400,200,"Zaloguj sie",64, 136, 253,255,255,255);
}
class Button {
boolean Pressed = false;
boolean Clicked = false;
PVector Pos = new PVector(0,0);
float Width;
float Height;
color Colour;
color textColour;
String Text;
Button(int x, int y, float w, float h, String t, int r, int g, int b, int tr, int tg, int tb) {
Pos.x = x;
Pos.y = y;
Width = w;
Height = h;
Text = t;
Colour = color(r,g,b);
textColour = color(tr,tg,tb);
}
void update() {
if (mousePressed == true && mouseButton == LEFT && Pressed == false) {
Pressed = true;
if (mouseX >= Pos.x && mouseX <= Pos.x+Width && mouseY >= Pos.y && mouseY <= Pos.y+Height) {
}
} else {
Clicked = false;
Pressed = false;
}
}
void render() {
noStroke();
fill(Colour);
rect(Pos.x,Pos.y,Width,Height);
fill(textColour);
textAlign(CENTER,CENTER);
text(Text,Pos.x+(Width/2),Pos.y+(Height/2));
}
boolean isClicked() {
return(Clicked);
}
}
将此添加到代码底部(在按钮 class 下方)。我不确定您是否真的需要 Pressed 和 Clicked 布尔值。
void mousePressed(){
if((mouseX >= login1.Pos.x) && (mouseX <= login1.Pos.x + login1.Width) && (mouseY >= login1.Pos.y) && (mouseY <= login1.Pos.y + login1.Height)){
println("You hit the login button.");
}
}