Cocos2dx使用TextField实现输入框
游戏login的时候必须要求玩家输入用户名、密码,还要可以删除。
cocostudio画一个textfield,直接读入好了;
textField类,继承读取的widget。
local textField = class("textField", function GUIReader:shareReader():widgetFromJsonFile(jsonPath) end)
--获得textField组件
function testField:ctor()
self.mTextField_input = tolua.cast(Helper:seekWidgetByName(self, "textField_m"), "ccui.TextField")
self:addCallback()
end
--注册回调
function testField:addCallback()
local keyListener = cc.EventListenerKeyBoard:create()
keyListener:registerScriptHandler(handler(self, self.onkeyPressed), cc.Handler.EVENT_KEYBOARD_PRESSED)
local currentScene = l_command.getCurrentScene()
currentScene:getEventDispatcher():addEventListenerWithSceneGraphPrioprity(keyListener, currentScene)
end
--删除事件,删除字母
function testField:onkeyPressed(keycode, event)
if keycode == cc.Keycode.KEYBACKSPACE then
local str = self.mTextField_input:getStringValue()
str = string.sub(str, 0, string.len(str) - 1)
self.mTextField_input:setText(str)
end
end
最新文章
- JSTL 核心标签库 使用
- NodeJS系列~第二个小例子,解决中文乱码的问题
- JMeter入门合集
- HDU 4081 Qin Shi Huang's National Road System [次小生成树]
- 数组对象Vector用法
- mvc5 + ef6 + autofac搭建项目(repository+uow)(二)
- CRM权限管理
- 2015苏州大学ACM-ICPC集训队选拔赛(3)题解
- 201621123067《JAVA程序设计》第一周学习总结
- python爬虫爬取代理IP
- CNCC2017中的深度学习与跨媒体智能
- Redis数据结构和常用API
- RESTful API浅谈
- spring-boot-actuator报错Full authentication is required to access this resource
- L1正则和L2正则的比较分析详解
- Mysql 视图使用
- MySQL常见错误代码及代码说明
- 20172321 2017-2018-2《Java程序设计》第三周学习总结
- spring框架学习(七)spring管理事务方式之xml配置
- 将数据库dbcp连接池改为c3p0连接池(草稿,别点)