How do I make my own text input with Spritefonts?

  • I've been able to make my own text input using keycodes and StringFromLastKeycode with the keyboard object, but I'm starting to run into issues with characters that have modifiers (like shift + 1 = "!", or shift + "/" = "?"). If I hold shift, it still returns "/" instead of "?". I also have issues with the down arrows (it actually returns an arrow instead of "up arrow", but due to it being a spritefont, just returns nothing).

    I'd really like to not have to bother with a text input object. It's a pixel art game at a very low scale and a textobject will ruin the way it looks. Is there anyway to do that with keycodes short of coding every single key individually?

  • This might not be what you are looking for but you can set CSS of the TextBox so that it is entirely invisible.

    I think it's "color" "background" and "border" all set to "transparent".

    You could then just set the text on changes made.

    The textBox will still do all the work but you won't see it.

    The trouble with any of these methods is getting a text position marker. That I don't know, apart from the entirely terrible method of having special characters which are added and subtracted from the string.

  • Sumyjkl

    I thought of that, but then if they happen to right click it, the menu will pop up and break the immersion of the game.

  • Hmm, true. I guess there's a chance of setting it invisible on right click, but it might trigger the UI event first.

    You will probably have to set up a dictionary with all the exceptions like 1 ! / ? and so on. Check if it has the item in the dictionary, if it doesn't then uppercase() it. If capslock is on, don't.

  • There are ways to disable right click via javascript.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • oosyrag - I tried playing with the HTML properties for the textbox. I've gotten some things hidden with the CSS lines, but honestly it's too much of a hassle to make it work.

    Sumyjkl - Yeah, that's pretty much what I ended up doing. Kind of a pain, but I suppose it works.

    The only thing I wish made sense the arrow keys returning a unicode symbol instead of text...

    Thanks for the advice!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)