Writing text from XML when interaction is detected
in
Programming Questions
•
3 months ago
Greetings forum,
I'm a bit of a newbie, but I'm able to follow tutorials, and have made some nice progress in the past few weeks. I'm trying to write a small program that will draw or display text on the screen that is loaded from an XML file when an interaction is detected. At the moment, I have the following:
XML xml;
PFont f;
void setup() {
f = createFont("Arial",16,true);
size(600,400);
background(255);
//load XML content
xml = loadXML("comments.xml");
XML[] comment = xml.getChildren("comment");
int index = int(random(comment.length));
String name = comment[index].getContent();
textFont(f, 24);
fill(0);
text(name,width/2,60);
}
This gets me close, every time the program is run a bit of text is pulled successfully from my XML file and displayed. I know the way I have it written is causing part of my issue, but obviously the program has to be closed and re-ran to display another selection. Can anyone point me in the right direction to keep the display window open, and display a new bit of text from the XML file when, say, a mouse click is detected, or the spacebar is pressed? If you want to offer pointers, they're also appreciated. Thanks!
1