XNA Guide text input - maximum length
Posted
by
simonalexander2005
on Game Development
See other posts from Game Development
or by simonalexander2005
Published on 2014-06-01T13:09:31Z
Indexed on
2014/06/01
15:58 UTC
Read the original article
Hit count: 407
so I am using Guide.BeginShowKeyboardInput to get the user to enter their username. I would like this to be limited to 20 characters, and it seems to break expected behaviour to let them input whatever they like and trim it later - so how would I go about limiting what they can input in the text box itself? I have the following code:
public string GetKeyboardInput(string title, string description, string defaultText, int maxLength)
{
if (input.CheckCancel())
{
useKeyboardResult = false;
KeyboardResult = null;
}
if (KeyboardResult == null && !Guide.IsVisible)
{
KeyboardResult = Guide.BeginShowKeyboardInput(PlayerIndex.One, title,
description, defaultText, null, null);
useKeyboardResult = true;
}
else if (KeyboardResult != null && KeyboardResult.IsCompleted)
{
string result = Guide.EndShowKeyboardInput(KeyboardResult);
KeyboardResult = null;
if (result == null)
{
useKeyboardResult = false;
return null;
}
if (useKeyboardResult)
{
KeyboardResult = null;
return result;
}
}
else //the user is still entering inputs
{
}
return null;
}
I assume the code I need would go in that final, empty else{} block, but I can't see any way to do this. Does anyone know how?
© Game Development or respective owner