Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] Text Input listener.  (Read 13719 times)
0 Members and 1 Guest are viewing this topic.
Offline MrPork
« Posted 2015-06-23 08:29:48 »

        So I made a little 3 rank high score system out of pure messines and that is working correctly for the most part. The part that I cannot figure out is how in the heck to get input from the android user.

Here is my full code sorry for the mess (It's 4:26 am) and I've been working on trying to fix this for the past few hours.
Ignore most of the dang nab nonsense, especially if its nonsense. It's just me trying to figure out how in the heck to get text input.

EDIT: Removed curse words, sorry im tired.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
if(!gameProcessor.player.isAlive()){
            if(gameProcessor.asteroidsDestroyed > HighScore1){
               HighScore3 = HighScore2;
                scorePreferences.putInteger("score3", HighScore3);
                HighScore2 = HighScore1;
                scorePreferences.putInteger("score2", HighScore2);
               HighScore1 = gameProcessor.asteroidsDestroyed;
               scorePreferences.putInteger("score1", HighScore1);
               MyTextListener listener = new MyTextListener();
               Gdx.input.getTextInput(listener , "New High Score!", "Input your name", "Your name");
                    HighScoreName1 = listener.input;
               scorePreferences.flush();
                                        loopMusic.stop();
               gameCore.setScreen(this);
               
               }
            }
            else if(gameProcessor.asteroidsDestroyed > HighScore2){
               HighScore3 = HighScore2;
               scorePreferences.putInteger("score3", HighScore3);
               HighScore2 = gameProcessor.asteroidsDestroyed;
               scorePreferences.putInteger("score2", HighScore2);
               MyTextListener listener = new MyTextListener();
               HighScoreName2 = null;
               Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
               HighScoreName2 = listener.returnText();
               scorePreferences.putString("name2", HighScoreName2);
               loopMusic.stop();
                    scorePreferences.flush();
                    gameCore.setScreen(this);
               }
            }
            else if(gameProcessor.asteroidsDestroyed > HighScore3){
               HighScore3 = gameProcessor.asteroidsDestroyed;
               scorePreferences.putInteger("score3", HighScore3);
               MyTextListener listener = new MyTextListener();
               Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
               HighScoreName3 = listener.returnText();
               HighScoreName3 = null;
               scorePreferences.putString("name3", HighScoreName3);
               loopMusic.stop();
               
               
               if(listener.hasInputed = true){
                  scorePreferences.flush();
                  gameCore.setScreen(this);
               }
            }
            else{
               loopMusic.stop();
               gameCore.setScreen(this);
            }
         }
     
      }

"f**k it, maybe it'll work." -Me
Offline MrPork
« Reply #1 - Posted 2015-06-23 08:31:33 »

Also, I just used the basic template from this thing

https://github.com/libgdx/libgdx/wiki/Simple-text-input

"f**k it, maybe it'll work." -Me
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #2 - Posted 2015-06-23 14:25:55 »

       So I made a little 3 rank high score system out of pure messines and that is working correctly for the most part. The part that I cannot figure out is how in the heck to get input from the android user.

Here is my full code sorry for the mess (It's 4:26 am) and I've been working on trying to fix this for the past few hours.
Ignore most of the dang nab nonsense, especially if its nonsense. It's just me trying to figure out how in the heck to get text input.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   private String newText;

   @Override
   public void input(String text) {
      System.out.println(text);
      newText = text;
   }

   @Override
   public void canceled() {
      System.out.println("Canceled");
   }
   
   public String getText(){
      return newText;
   }

The input method is called after you press "okay".
The canceled is called after you cancel the dialog ("cancel", quit button, escape).

1  
2  
3  
4  
5  
6  
7  
8  
9  
            Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
            if (listener.getText() != null)
            {
               HighScoreName2 = listener.getText();
               System.out.println(HighScoreName2);
               ...
               ..
               .
            }


Or you can use TextField (txtField.getText()): http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/TextField.html

_ Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MrPork
« Reply #3 - Posted 2015-06-23 15:28:22 »

I tried doing that and the game is still going ahead and restarting the game withought me pressing ok after I input my text. The game restarts with gameCore.setScreen(this);. When I now reach the the top score all 3 score inputs get executed, I thought if else was supposed to stop this? And finally, now the game isn't even accepting my high scores, the table always stays at 0 which I suppose means the preference aren't flushing.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
   if(!gameProcessor.player.isAlive()){
            if(gameProcessor.asteroidsDestroyed > HighScore1){
               HighScore3 = HighScore2;
                scorePreferences.putInteger("score3", HighScore3);
                HighScore2 = HighScore1;
                scorePreferences.putInteger("score2", HighScore2);
               HighScore1 = gameProcessor.asteroidsDestroyed;
               scorePreferences.putInteger("score1", HighScore1);
               MyTextListener listener = new MyTextListener();
               Gdx.input.getTextInput(listener , "New High Score!", "Input your name", "Your name");
               
               if(listener.returnText() != null){
                  HighScoreName1 = listener.returnText();
                  scorePreferences.putString("name1", HighScoreName1);
                  scorePreferences.flush();
                  loopMusic.stop();
                  gameCore.setScreen(this);
               }
            }
           
            else if(gameProcessor.asteroidsDestroyed > HighScore2){
               HighScore3 = HighScore2;
               scorePreferences.putInteger("score3", HighScore3);
               HighScore2 = gameProcessor.asteroidsDestroyed;
               scorePreferences.putInteger("score2", HighScore2);
               MyTextListener listener = new MyTextListener();
               Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
               
               if(listener.returnText()!= null){
               HighScoreName2 = listener.returnText();
               scorePreferences.putString("name2", HighScoreName2);
               loopMusic.stop();
               scorePreferences.flush();
               gameCore.setScreen(this);
                  }
               }
            else if(gameProcessor.asteroidsDestroyed > HighScore3){
               HighScore3 = gameProcessor.asteroidsDestroyed;
               scorePreferences.putInteger("score3", HighScore3);
               MyTextListener listener = new MyTextListener();
               Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
               
               if(listener.returnText() != null){
               HighScoreName3 = listener.returnText();
               scorePreferences.putString("name3", HighScoreName3);
               loopMusic.stop();
               scorePreferences.flush();
               gameCore.setScreen(this);
                  }
               }
           
            else{
               loopMusic.stop();
               gameCore.setScreen(this);
            }
      }

"f**k it, maybe it'll work." -Me
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #4 - Posted 2015-06-23 16:24:20 »

This code is in your update() loop?

Because you need to set the scorePreferences and change the HighScore1, 2, 3 only once.
If "asteroidsDestroyed > HighScore1", your HighScore2 will receive the old HighScore1 value, so in the next loop the "asteroidsDestroyed > HighScore2" will return true and will create a listener again ("When I now reach the the top score all 3 score inputs get executed").
And the screen is restarted because after doing this, the code enter in the last Else. I think you can solve this with only one boolean variable to allow your save state to be executed once.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
//Global vars
private boolean isScoreSaved = false; //not saved
private int scorePosition = 0; //Only to know which Highscore was saved
private MyTextListener listener = new MyTextListener();


....................


   if(!gameProcessor.player.isAlive() && !isScoreSaved) //only if score not saved
   {
      if(gameProcessor.asteroidsDestroyed > HighScore1)
      {
         HighScore3 = HighScore2;
         scorePreferences.putInteger("score3", HighScore3);
         HighScore2 = HighScore1;
         scorePreferences.putInteger("score2", HighScore2);
         HighScore1 = gameProcessor.asteroidsDestroyed;
         scorePreferences.putInteger("score1", HighScore1);
         Gdx.input.getTextInput(listener , "New High Score!", "Input your name", "Your name");
         
         isScoreSaved = true;
         scorePosition = 1;
      }
     
      else if(gameProcessor.asteroidsDestroyed > HighScore2)
      {
         HighScore3 = HighScore2;
         scorePreferences.putInteger("score3", HighScore3);
         HighScore2 = gameProcessor.asteroidsDestroyed;
         scorePreferences.putInteger("score2", HighScore2);
         Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
         
         isScoreSaved = true;
         scorePosition = 2;
      }
         
      else if(gameProcessor.asteroidsDestroyed > HighScore3)
      {
         HighScore3 = gameProcessor.asteroidsDestroyed;
         scorePreferences.putInteger("score3", HighScore3);
         Gdx.input.getTextInput(listener, "New High Score!", "Input your name", "Your name");
         
         isScoreSaved = true;
         scorePosition = 3;
      }
         
      else //No highscore
      {
         loopMusic.stop();
         gameCore.setScreen(this);
      }
   }
   else if (!gameProcessor.player.isAlive() && isScoreSaved) //if score was saved
   {
      if(listener.returnText() != null)
      {
         if (scorePosition == 1)
            scorePreferences.putString("name1", listener.returnText());
         else if (scorePosition == 2)
            scorePreferences.putString("name2", listener.returnText());
         else if (scorePosition == 3)
            scorePreferences.putString("name3", listener.returnText());
           
         loopMusic.stop();
         scorePreferences.flush();
         gameCore.setScreen(this);
      }
   }

_ Wink
Offline MrPork
« Reply #5 - Posted 2015-06-23 17:10:44 »

I wish I could give you multiple medals for this. Thank you for teaching me a new way of thinking!  Grin

"f**k it, maybe it'll work." -Me
Offline MrPork
« Reply #6 - Posted 2015-06-23 17:19:35 »

Quick question though, how does this work??? I thought you needed bracket for if statements

1  
2  
3  
4  
5  
6  
 if (scorePosition == 1)
                  scorePreferences.putString("name1", listener.returnText());
               else if (scorePosition == 2)
                  scorePreferences.putString("name2", listener.returnText());
               else if (scorePosition == 3)
                  scorePreferences.putString("name3", listener.returnText());

"f**k it, maybe it'll work." -Me
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #7 - Posted 2015-06-23 17:38:55 »

Quick question though, how does this work??? I thought you needed bracket for if statements
If you have only one instruction inside of if statement (works with other statements), you don't need to use brackets.  Cheesy

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
//One instruction
if (x > 0)
   x = 0;
else
   x = 1;
   
//Two or more instructions
if (x > 0)
{
   x = 0;
   System.out.println(x);
}
else
{
   x = 1;
   System.out.println(x);
}

_ Wink
Offline MrPork
« Reply #8 - Posted 2015-06-23 17:41:49 »

There is still on thing that is bothering me though, the game is still restarting before asking for the input.

"f**k it, maybe it'll work." -Me
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #9 - Posted 2015-06-23 17:50:39 »

Quick question though, how does this work??? I thought you needed bracket for if statements
If you have only one instruction inside of if statement (works with other statements), you don't need to use brackets.

Skipping the curly brackets for single statements is widely regarded as a bad practice, as you are likely to add another statement overlooking the fact it is not enclosed by the if.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MrPork
« Reply #10 - Posted 2015-06-23 17:52:11 »

I wasn't on planning on using that way anyways. It seemed like it would get confusing very quickly.

"f**k it, maybe it'll work." -Me
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #11 - Posted 2015-06-23 17:56:53 »

There is still on thing that is bothering me though, the game is still restarting before asking for the input.
We have only two "setScreen".

The only way the game can change the screen before the input is here:
1  
2  
3  
4  
5  
      else //No highscore
      {
         loopMusic.stop();
         gameCore.setScreen(this);
      }

This only happens if the gameProcessor.asteroidsDestroyed <= HighScore3.

The second way, only executes if isScoreSaved == true AND if listener.returnText() != null.

Can you show your listener.returnText()?

Edit-
I tested here and is working (desktop version).

_ Wink
Offline MrPork
« Reply #12 - Posted 2015-06-23 18:09:42 »

This is my returnText() in my Text input listener

   
1  
2  
3  
public String returnText(){
      return input;
   }


I'm also now trying to organize my High score names so that they drop down with their points too. Current problem is that if I get a 1st place high score and write my name, then get a 2nd place high score, the 1st place name still drops down to the 2nd place leaving the 1st place without a name. Sorry if I frankensteined your code, I'm going full on rage mode on it (plus im stupid).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
else if (!gameProcessor.player.isAlive() && isScoreSaved) //if score was saved
         {
          if (scorePosition == 1){
                  HighScoreName3 = HighScoreName2;
                  scorePreferences.putString("name3", HighScoreName3);
                  HighScoreName2 = HighScoreName1;
                  scorePreferences.putString("name2", HighScoreName2);
                  scorePreferences.putString("name1", listener.returnText());
                  isScoreSaved = false;
                  gameCore.setScreen(this);
               }
             if (scorePosition == 2){
                  HighScoreName3 = HighScoreName2;
                  scorePreferences.putString("name3", HighScoreName3);
                  scorePreferences.putString("name2", listener.returnText());
                  isScoreSaved = false;
                  gameCore.setScreen(this);
               }
              if (scorePosition == 3){
                  scorePreferences.putString("name3", listener.returnText());
                  isScoreSaved = false;
                  scorePosition = 0;
                  gameCore.setScreen(this);
         
               }
                 
               loopMusic.stop();
               scorePreferences.flush();
             
         }

"f**k it, maybe it'll work." -Me
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #13 - Posted 2015-06-23 18:35:22 »

This is my returnText() in my Text input listener

   
1  
2  
3  
public String returnText(){
      return input;
   }


I'm also now trying to organize my High score names so that they drop down with their points too. Current problem is that if I get a 1st place high score and write my name, then get a 2nd place high score, the 1st place name still drops down to the 2nd place leaving the 1st place without a name. Sorry if I frankensteined your code, I'm going full on rage mode on it (plus im stupid).
No problem, I forgot about the other Highscore names xD.
By the way, in your Override input() method in your myTextInputListener you are setting input = text, right?

You need to check if(listener.returnText() != null), your input will only receive the string value after you hit "Okay", before that it always returns null. So, the screen will restart ONLY after you press "okay" button in dialog. Your current code is saving null in your scorePreferences.

I tested this and is working, you can write your name and after you click on "OK" button, the screen is restarted (now with your changing name code).
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
else if (!gameProcessor.player.isAlive() && isScoreSaved) //if score was saved
         {
          if(listener.returnText() != null)
          {
            if (scorePosition == 1){
                 HighScoreName3 = HighScoreName2;
                 scorePreferences.putString("name3", HighScoreName3);
                 HighScoreName2 = HighScoreName1;
                 scorePreferences.putString("name2", HighScoreName2);
                 HighScoreName1 = listener.returnText();
                 scorePreferences.putString("name1", HighScoreName1);
               }
             if (scorePosition == 2){
                 HighScoreName3 = HighScoreName2;
                 scorePreferences.putString("name3", HighScoreName3);
                 HighScoreName2 = listener.returnText();
                 scorePreferences.putString("name2", HighScoreName2);
               }
              if (scorePosition == 3){
              HighScoreName3 = listener.returnText();
                 scorePreferences.putString("name3", HighScoreName3);
               }
            scorePreferences.flush();    
            loopMusic.stop();  
            gameCore.setScreen(this);
         }
         }


BTW, This prints "null" in console before you click on "ok": System.out.println(listener.returnText());

_ Wink
Offline MrPork
« Reply #14 - Posted 2015-06-23 18:57:43 »

Works perfectly now, thanks again! Well, also we forgot to set the isScoreSaved back to false after we set the names. Or else my game just gets stuck in the play State.  Grin Grin

"f**k it, maybe it'll work." -Me
Offline MrPork
« Reply #15 - Posted 2015-06-23 20:19:58 »

Ok so I noticed that when the dialogue to enter your name comes up, you can press the cancel button which will do nothing but glitch out my game and make you invincible. I can't figure out how to make the game go back to the menu screen if a person accidentaly presses that button.

According to the wiki:

Quote
The canceled() method will be called if the user closed the dialog on the desktop or pressed the back button on Android.

And that is indeed true. Meaning, nothing gets called if I press the cancel button on the dialogue on android. So how would I make that button return something?

"f**k it, maybe it'll work." -Me
Offline chrislo27
« Reply #16 - Posted 2015-06-23 20:44:05 »

Are you overriding the cancelled method in the input listener? You can override it to do something when it gets called.

Meaning, nothing gets called if I press the cancel button on the dialogue on android.

I might be interpreting your question incorrectly. Is the method not actually getting called or just not doing anything?
Offline MrPork
« Reply #17 - Posted 2015-06-23 20:50:02 »

The text input listener has no method for getting a notification of wether the cancel button has been pressed when the dialogue is up. An example is the picture below, the user can enter their name and press ok and be brought back to the menu and restart, but there is no method that I can find that makes the cancel button do something instead of just close the dialogue. I would like to know when that button is pressed to return back to the menu as well.


"f**k it, maybe it'll work." -Me
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #18 - Posted 2015-06-23 20:55:06 »

The text input listener has no method for getting a notification of wether the cancel button has been pressed when the dialogue is up. An example is the picture below, the user can enter their name and press ok and be brought back to the menu and restart, but there is no method that I can find that makes the cancel button do something instead of just close the dialogue. I would like to know when that button is pressed to return back to the menu as well.

Can you not just put your own code inside the implementation of the listener? So inside public void cancelled() you could put something like

1  
2  
3  
public void cancelled(){
    game.setScreen(new MainMenu(game));
}


This is if i'm understanding the issue

Hey, you! Back to work
Offline MrPork
« Reply #19 - Posted 2015-06-23 20:56:26 »

Yes, I can. The problem is though, that that method only responds to closing the dialogue on desktop or pressing the back button on the android device, not hitting that cancel button.

"f**k it, maybe it'll work." -Me
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #20 - Posted 2015-06-23 21:00:45 »

Yes, I can. The problem is though, that that method only responds to closing the dialogue on desktop or pressing the back button on the android device, not hitting that cancel button.

Ahh I see, I just quickly read the little bit of documentation on it. I've never really dealt with handling events for different devices but I wonder if their is someway they you can link up the cancel button with the Android back button.

I was thinking of some custom listener but I don't know how to access the Android back button/or how to tell if a user is using Desktop or Android

Hey, you! Back to work
Offline CopyableCougar4
« Reply #21 - Posted 2015-06-23 21:06:12 »

If I am reading this thread correctly, you want to handle the back button on Android devices?

If so, I would check out this StackOverflow post: http://stackoverflow.com/a/7241246

EDIT: You could also check if the device is android, and if so do the Android specific stuff yourself. I don't have much experience with libgdx or android, though.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
public void getTextInput (final TextInputListener listener, final String title, final String text, final String hint) {
      handle.post(new Runnable() {
         public void run () {
            AlertDialog.Builder alert = new AlertDialog.Builder(context);
            alert.setTitle(title);
            final EditText input = new EditText(context);
            input.setHint(hint);
            input.setText(text);            
            input.setSingleLine();
            alert.setView(input);
            alert.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
               public void onClick (DialogInterface dialog, int whichButton) {
                  Gdx.app.postRunnable(new Runnable() {
                     @Override
                     public void run () {
                        listener.input(input.getText().toString());
                     }
                  });
               }
            });
            alert.setNegativeButton(context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
               public void onClick (DialogInterface dialog, int whichButton) {
                  Gdx.app.postRunnable(new Runnable() {
                     @Override
                     public void run () {
                        listener.canceled();
                     }
                  });
               }
            });
            alert.setOnCancelListener(new OnCancelListener() {
               @Override
               public void onCancel (DialogInterface arg0) {
                  // Handle this differently. called when back button hit.
               }
            });
            alert.show();
         }
      });
   }

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline MrPork
« Reply #22 - Posted 2015-06-23 21:09:53 »

I am actually trying to get feedback from the cancel button in the picture above.

"f**k it, maybe it'll work." -Me
Offline CopyableCougar4
« Reply #23 - Posted 2015-06-23 21:11:02 »

I think my edit could help you. Check if the device is android or not and then run that android-specific code for handling input? I don't have experience with libgdx so I don't know how hard that would be to do.

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline MrPork
« Reply #24 - Posted 2015-06-23 21:14:29 »

Welp, I'm an everything noob. So I suppose i'll end up researching this for a couple days now xD

"f**k it, maybe it'll work." -Me
Offline chrislo27
« Reply #25 - Posted 2015-06-23 21:20:32 »

The methods in TextInputListener here have two methods: input(String) and canceled(). Note that they spelt cancelled with one l for some reason...

Could we see the code for your input listener?
Offline MrPork
« Reply #26 - Posted 2015-06-23 21:21:40 »

Here you go!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
public class MyTextListener implements TextInputListener {

   public String input = null;
   GameCore core;
   
   public MyTextListener(GameCore core){
      this.core = core;
      input = null;
   }

   
   @Override
   public void input(String text) {
      input = text;
     
     
   }
   
   public String returnText(){
      return input;
   }
   
   public void dispose(){
      input = null;
   }

   @Override
   public void canceled() {
      dispose();
      core.setScreen(core.playScreen);
     
   }

}

"f**k it, maybe it'll work." -Me
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #27 - Posted 2015-06-24 01:55:52 »

What do you want to do when the player hit "cancel" ?

In games, usually they just add an unknown name (if the player hits cancel unconsciously, he don't lose the score).

1  
2  
3  
4  
@Override
   public void canceled() {
      input = "Unknown Name"; //Or "Unknown Player"
   }

_ Wink
Offline MrPork
« Reply #28 - Posted 2015-06-24 01:58:48 »

I now have it so that I just tap the screen to restart if the player accidentally presses cancel.

"f**k it, maybe it'll work." -Me
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (81 views)
2019-09-04 15:33:17

hadezbladez (4336 views)
2018-11-16 13:46:03

hadezbladez (1547 views)
2018-11-16 13:41:33

hadezbladez (4462 views)
2018-11-16 13:35:35

hadezbladez (871 views)
2018-11-16 13:32:03

EgonOlsen (4152 views)
2018-06-10 19:43:48

EgonOlsen (4855 views)
2018-06-10 19:43:44

EgonOlsen (2803 views)
2018-06-10 19:43:20

DesertCoockie (3707 views)
2018-05-13 18:23:11

nelsongames (3998 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!