当 mousePressed() 每 3 秒为假时,我想让文本显示在屏幕上,我在 mousePressed() 函数中设置了一个布尔值“是否”,当它为假时,我从文本文件中获取字符串。但似乎我的逻辑是错误的。有人知道这个问题吗?
Zoog[]zoog = new Zoog[1];
float count=0;
int xpos =0;
int ypos =0;
String message="haha";
String newone="";
String t="\n";
int ntextsize = 20;
int nopacity =200;
int thistime = 0;
int thiscount = 0;
String[]lines;
//Zoog zoog;
boolean whether;
void setup() {
size(400, 400);
xpos = int(random(width/2-200, width/2+40));
ypos = int(random(height/2, height/2-40));
zoog[0] = new Zoog(xpos,ypos,message,nopacity);
}
void draw(){
background(255,255,255);
for(int i=0; i<zoog.length; i++){
// if(millis()-thistime>4000){
// zoog[i].disappear();
// }
zoog[i].jiggle();
zoog[i].display();
}
whether = false;
lines = loadStrings("data.txt");
if(whether!=true){
createnew(int(random(width)), int(random(height)), lines[int(random(lines.length))],150);
}
}
void mousePressed(){
whether = true;
count = count + 1;
// int thiscount = 0;
if(count%3 ==0){
xpos=int(random(30, width-30));
ypos=int(random(10, height-10));
}
else{
ypos = ypos+50;
}
nopacity = int(random(100,255));
createnew(xpos,ypos,message,nopacity);
}
void createnew(int xxpos, int yyos, String mmessage, int nnopacity){
Zoog b = new Zoog(xpos,ypos,message,nopacity);
zoog =(Zoog[]) append(zoog,b);
}
我的问题对应的功能是:
lines = loadStrings("data.txt");
if(whether!=true){
createnew(int(random(width)), int(random(height)), lines[int(random(lines.length))],150);
}
}
和
void createnew(int xxpos, int yyos, String mmessage, int nnopacity){
Zoog b = new Zoog(xpos,ypos,message,nopacity);
zoog =(Zoog[]) append(zoog,b);
}