• 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

  • 相关阅读:
    (3)C++复合类型
    (2)C++基本类型
    (7)js调试
    Oracle语句优先级
    oracle排序问题
    jsp四大对象
    postgresql时间加减计算
    全角空格,跟汉字一样宽
    bzoj1433 [ZJOI2009]假期的宿舍 最大流
    BZOJ 1264 AHOI2006 基因匹配Match 动态规划+树状数组
  • 原文地址:https://www.cnblogs.com/alex-zhou/p/4277810.html
Copyright © 2020-2023  润新知