How to make text appear for x millis() after key input?

I made a class in which a player draws some text from x millis() to y millis() when function say("hi",x,y) is used. It uses millis(); Example:

Player p;

void setup(){
  //initializes the sketch
}
void draw(){
  p.say("Hi!",1000,2500)//Hi!
  p.say("i come after mousePressed",x,y)//Here comes the problem!
}
//end

I tried playing with millis-int thingie but the problem is that the variable changes per frame. Please help me.

Tagged:

Answers

  • edited October 2017

    here, I tried

    final int mil=millis();
      text(mil,width/2,height/25);
      main.say("That's the timer above!",mil,mil+5); 

    Does not work

  • Have a variable that tracks if the text should be drawn. Have a variable that remembers the time (which is a positive number of milliseconds elapsed since the sketch started) at which the text should disappear.

    When your sketch starts, the text should not appear, and the time it should disappear does not matter.

    When you draw your sketch, check if the text should be drawn. If it should, draw it, then check if the current time (millis()) is greater than the time at which the text should disappear. If it is, remember that the text should stop being drawn.

    When a key is pressed, remember that the text needs to be displayed and determine the time at which it should stop being displayed. You can work out that time by getting the current time (millis()) and adding on some number of milliseconds (try 1000).


    These directions translates almost directly into code.

    Attempt to write this code and post your attempt for more help.

Sign In or Register to comment.