1. Create an input box
self.selectcount= Ccui. Editbox:create (Cc.size (100,30), "") --Input frame size, background image
self.selectCount:setPosition (CC.P (Tf:getpositionx (), Tf:getpositiony ()))
Self.selectCount:anch (CC.P (0.5,0.5))
self.selectCount:setFontSize (+)
Self.selectCount:setFontColor (cc.c3b (255,255,255))
Self.selectCount:setReturnType (CC. Keyboard_returntype_send) --Input keyboard return type, Done,send,go, etc.
Self.selectCount:setInputMode (CC. Editbox_input_mode_numeric) --input models, such as integer types, URLs, phone numbers, etc., will detect compliance
Self.selectCount:registerScriptEditBoxHandler (function (eventname,sender) self:editboxhandle (EventName, Sender) --the event of the input box, mainly with the cursor moved in, the cursor is moved out, and the input content changes, etc.
self.widget:addChild (Self.selectcount)
Self.selectCount:setHACenter () --The input content anchor is centered, and unlike Anch, Anch is used to determine the position of the control, and here is where the input is determined to unfold (... No, I don't. Test it yourself)
2. Event handling
function Troopsoldieritem:editboxhandle (Streventname,sender)
if Streventname = = "began" Then
Sender:selectedall () --Cursor entry, select all contents
ElseIf Streventname = = "Ended" Then
--Called when the edit box loses focus and the keyboard disappears
ElseIf Streventname = = "return" Then
--Called when the user clicks on an area other than the keyboard of the edit box, or when the return button of the keyboard is clicked
ElseIf Streventname = = "Changed" Then
--called when the input content changes
End
End
COCOS2DX Lua Input Box usage (editbox)