Button to infinitely generate text

#1

I am working on a project that include a bunch of buttons that when pressed reveal text on the screen. Right now the text disappears when you click off the button. Would it be possible to either a) have the text remain when you click another button (because right now when you click another button the previous text disappears), or b) each time the button is pressed a duplicate of the text appears in a random location on the screen so that if you keep clicking buttons the screen will gradually fill?

This is what I have for each button at the moment.

if(bIsClicked){
        ofSetColor(0);
        ofDrawBitmapString("This is random text for the sake of this example.", 500, 900);}
#2

hello,
You can store the text position in vector.
Example code below, I didn’t compile but hope it shows an idea.

// ofApp.h
vector<glm::vec2> textPositions;
// ofApp.cpp
void ofApp::update(){
 if(bIsClicked){
   float x = ofRandom(0, ofGetWidth());
   float y = ofRandom(0, ofGetHeight());    
   textPositions.emplace_back(x, y);
  }
}

void ofApp::draw(){
  for(auto & p : textPositions){
    ofSetColor(0);
    ofDrawBitmapString("your text here", p.x, p.y);
  }
}
1 Like
#3

this is almost exactly what I want! right now the text duplicates very fast, is there a way to make it so that it is just with each press of the button? if not no problem, I will use this, it’s pretty much perfect for my project.

Edit:
Actually I think this is perfect after having tested for a little bit. Thank you so much!

1 Like