加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos-js 创建textfield和EditBox

发布时间:2020-12-14 21:11:33 所属栏目:百科 来源:网络整理
导读:// Create the textfield var textField = new ccui.TextField( "PlaceHolder" , "Marker Felt" ,30); textField.x = widgetSize.width / 2.0; textField.y = widgetSize.height / 2.0; textField.addEventListener( this .textFieldEvent, this ); this ._m

// Create the textfield

var textField = new ccui.TextField("PlaceHolder","Marker Felt",30);

textField.x = widgetSize.width / 2.0;

textField.y = widgetSize.height / 2.0;

textField.addEventListener(this.textFieldEvent,this);

this._mainNode.addChild(textField);


return true;

}

return false;

},


textFieldEvent: function (textField,type) {

switch (type) {

case ccui.TextField.EVENT_ATTACH_WITH_IME:

var widgetSize = this._widget.getContentSize();

textField.runAction(cc.moveTo(0.225,

cc.p(widgetSize.width / 2,widgetSize.height / 2 + textField.height / 2)));

this._topDisplayLabel.setString("attach with IME");

break;

case ccui.TextField.EVENT_DETACH_WITH_IME:

var widgetSize = this._widget.getContentSize();

textField.runAction(cc.moveTo(0.175,cc.p(widgetSize.width / 2.0,widgetSize.height / 2.0)));

this._topDisplayLabel.setString("detach with IME");

break;

case ccui.TextField.EVENT_INSERT_TEXT:

this._topDisplayLabel.setString("insert words");

break;

case ccui.TextField.EVENT_DELETE_BACKWARD:

this._topDisplayLabel.setString("delete word");

break;

default:

break;

}

}


this._zhanghao = new cc.EditBox(cc.size(360.00,53.00),new cc.Scale9Sprite("DLinput.png"))

this._zhanghao.setName("zhaoguanghui");

this._zhanghao.setPosition(647,355);

this._zhanghao.setDelegate(this);

this._zhanghao.setMaxLength(20);

this._zhanghao.setPlaceHolder("点击输出账号");

this._zhanghao.setInputFlag(cc.EDITBOX_INPUT_FLAG_SENSITIVE);//修改为不使用密文

this._zhanghao.setInputMode(cc.EDITBOX_INPUT_MODE_ANY);

this.addChild(this._zhanghao,1,10);

return true;

},

editBoxEditingDidBegin: function (editBox) {

cc.log("editBox " + editBox.getName() + " DidBegin !");

},


editBoxEditingDidEnd: function (editBox) {

cc.log("editBox " + editBox.getName() + " DidEnd !");

},


editBoxTextChanged: function (editBox,text) {

cc.log("editBox " + editBox.getName() + ",TextChanged,text: " + text);

},


editBoxReturn: function (editBox) {

cc.log("editBox " + editBox.getName() + " was returned !");

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读