Hello!
I am a newbie for LOVE programming but I learn fast I think. But I have a small issue with one thing. At the beginning of my game, I want to ask the player to enter their desired nickname. I'm programming in lua Love2D.
I want a text box to appear: Your Nickname, then the player enters his nickname, and presses enter when they're done.
I can't get it to work.
Thank you.
How to program entering the nickname?
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to program entering the nickname?
Hi and welcome to the forums!
You draw the textbox however you want, with just a few rectangles, or whatever.
You get input with the love.textinput callback. It works per-character, so you'll need to append data to a string (and possibly delete a character if backspace is pressed... optionally you can also implement cursor movement with left/right and deleting to the right with the delete key.)
You do need to draw the already existing string as well so the user gets feedback on how much they've typed (a simple love.graphics.print(str) will do the job, with str being where you store the nickname.)
You probably want to stop detecting entered characters when enter/return is pressed, love.keypressed callback is probably the best option for this (and the detection of other non-character inputs as well, like backspace, left, right, delete, ...)
You draw the textbox however you want, with just a few rectangles, or whatever.
You get input with the love.textinput callback. It works per-character, so you'll need to append data to a string (and possibly delete a character if backspace is pressed... optionally you can also implement cursor movement with left/right and deleting to the right with the delete key.)
You do need to draw the already existing string as well so the user gets feedback on how much they've typed (a simple love.graphics.print(str) will do the job, with str being where you store the nickname.)
You probably want to stop detecting entered characters when enter/return is pressed, love.keypressed callback is probably the best option for this (and the detection of other non-character inputs as well, like backspace, left, right, delete, ...)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: How to program entering the nickname?
Using a GUI library is also an option There are some in the Libraries forum, or check https://github.com/love2d-community/awesome-love2d; also see my sig for Gspöt. For a simple edit box like this, Gspöt might suffice.
Who is online
Users browsing this forum: Bing [Bot] and 6 guests