COCOS2DX Lua Input Box usage (editbox)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.