How to delete button after certain time

I am trying to create a rhythm game in openframeworks, and I was trying to find a way to delete buttons after they are clicked. I tried setting a timer so that it appeared in a certain time frame and had a boolean keep track of if it was clicked and if it was it would not set the button. However, after the time frame, even though I can’t see the button anymore, I can still click it. How can I delete the button instead of not displaying it?

My take is that it depends how you are defining your buttons, did you write a button class or are you using a plugin etc. Are your buttons in a list? If you provide the important parts of your code it can help!

If you’re looking for a dirty hack you can move the button off screen when its clicked, along with not drawing it. You can also put the Boolean inside the buttons functionality and that it should only take action if it is the first time it is clicked. So its like having an invisible button that doesn’t do anything. But if you’re looking to scale the game I don’t recommend these.

The way I created my button was like this:
ofPoint timedButton; in header
In draw method:
where timer keeps track of time elapsed
if (timer >= 2000 && !clickedTimedButton && timer <= 3000) {
ofCircle(timedButton, radius);
Should I create a button class or use a plugin instead?

depends if your game is going to get more complicated, like if you are going to be making anything more than simple buttons id recommend looking at OF’s build in ofxGui
you can see examples .

otherwise you can add a line after that code you provided
else{ timedButton.set(-300,-300);} // this simply moves your button to an unreachable location.

set is only changing the location. the ofxpoint still exists if you don’t set it each frame.