简体   繁体   中英

Make each word within a list appear and then disappear in Processing

I'm completely new to Processing, very enthusiastic, but really stumped at the first hurdle. I really appreciate the fact that this is surely very basic stuff, but would be so happy if anyone could give me a hand to move on a bit.

I'm looking for a way to input a long-ish list of words which will then display one by one, with each appearing for 1 second and then disappearing.

I've found a way to print a whole sentence and have words disappear individually, and tried the below which seems to work a little better. The problem with this is I can't work out how to add more words to the loop, it seems to only consider one against the other. Is there an entirely different approach I can take?

Many thanks, this is where I'm up to

String Carol = "Carol";
String Charlotte = "Charlotte";
String Ellen = "Ellen";
String displayed ="";

int interval = 1000; // s
int time;

PFont font;

void setup() {
size(500, 500);
font = createFont("arial", 44);
background(0);
displayed = Carol;
time = millis();
textFont(font);
fill(255);
}

void draw() {
background(0);
text(displayed, width/2 - textWidth(displayed)/2, height/2);

if (millis() - interval > time) {
displayed = displayed.equals(Carol)? Charlotte:Carol;
time  = millis();

Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense.

You need to break your problem down into smaller steps and then take those steps on one at a time. For example, can you write a simple example program that just shows a single hard-coded string? Now can you make it so the string disappears after 1 second? Then try to add a second hard-coded string that appears after the first one.

Then if you get stuck, you can post a MCVE along with a specific technical question. Good luck.

Hint: You can probably use the millis() function or the frameCount variable. The Processing reference is your friend. But again, start simple and work your way forward in small incremental steps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM