Jump to content
  • Advertisement
Sign in to follow this  
BaconDevil Gaming

Displaying Text on The screen for a certain amount of time

This topic is 940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So Ive been at this for weeks and for what ever reason I cannot figure this out.

 

What I need to do is when the player hits an action key the game updates a boolean so a String is constantly displayed on the screen.

 

Then, I need a timer to activate which, after a certain amount of time, updates a boolean that allows the player to hit the action key and proceed to the next String.

 

I have found no tutorials that have helped me on this subject. I need to figure this out so I can proceed with my game. Please help.

Share this post


Link to post
Share on other sites
Advertisement
Why do you need those two booleans? It seems you only need the time of the last event. If enough time has elapsed, you let the player advance.


As for not finding a tutorial, you'll find logic like this tends to not have tutorials. They are details the programmer needs to reason out on their own.

Share this post


Link to post
Share on other sites


Why do you need those two booleans?

my issue is constantly displaying the text. it only shows when I hold the action key. It doesn't stick. I was thinking that by setting a boolean to true I could tell java that

while(boolean = true){

       g.drawString(...)

}

Share this post


Link to post
Share on other sites

You could do something like this:

while (time < timeWhenTextShouldDissapear){
    g.drawString(...)
}

Just update timeWhenTextShouldDissapear whenever you need the text to appear.

Share this post


Link to post
Share on other sites

You could implement a little state machine type thing. Your problem sounds like it has several discrete states, the initial waiting state, the showing string state, the state a user can now press the action button. You could neatly wrap that up in a simple object.

 

Your object might have a simple enum with a few states, a variable with what state it is in and a few methods such as OnAction(). The action method might look something like:

void OnAction()
{
   switch(state)
   {
      case Idle:
         state = ShowingString;
         break;
      case ShowingString:
         // Some logic to check the time has passed
         if(timePassed)
            state = next state;
            break;
      // etc
   }
}


In some of your other methods they will look similar, maybe you have an Update method that is doing your timings, that would behave differently depending on the state. Perhaps you have methods that can be called to check if a string should be displayed and what that string is. State machines are great, they are a little bit more effort than some of the other suggestions but they expand really well. I think as soon as you start to need several isolated variables to get something done it is a good candidate to making into a separate object.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!