电影引号只是快速连续出现,而不是从文本文档中拉出一个随机电影引用的预期效果。
理想情况下,我希望点击鼠标即可显示新报价。
试图使数组和索引成为一个全局变量,但由于某种原因,文本不会显示。
PImage wallpaper;
void setup() {
size(600, 600);
wallpaper = loadImage("Theatrescreen.png");
}
void draw() {
background(wallpaper);
String[] moviequotes = loadStrings("moviequotes.txt");
int index = int(random(moviequotes.length));
text(moviequotes[index], mouseX, mouseY);
}
void mousePressed() {
}
答案 0 :(得分:1)
draw()
内的代码在无限循环中执行。我认为这是你的问题。见Processing Reference - draw()。要解决此问题,请考虑使用noloop()
。请参阅Processing Reference - noloop()。
答案 1 :(得分:0)
您对Random的实现不正确。尝试这样的事情:
void draw() {
background(wallpaper);
String[] moviequotes = loadStrings("moviequotes.txt");
Random randIndex = new Random();
int index = randIndex.nextInt(moviequotes.length); // generate a random index from 0 to movieqoutes.length
text(moviequotes[index], mouseX, mouseY);
}
答案 2 :(得分:0)
您正在为每个绘制周期生成一个新的随机电影报价。这意味着很多(每秒钟超过25个依赖于帧速率)。
您可以像这样设置帧速率:
void setup() {
frameRate(1);
}
或在绘制循环中添加一个计数器,以便您偶尔生成一次新引号