cocoscreator typescript虚拟键盘的输入事件的简单实例

cocoscreator typescript虚拟键盘的输入事件的简单实例_第1张图片
(1)在上面素材中加入Button,在显示层加入五个lable作为房间号码显示层。
cocoscreator typescript虚拟键盘的输入事件的简单实例_第2张图片
(2)绑定button事件和自定义按钮的显示数字 如图cocoscreator typescript虚拟键盘的输入事件的简单实例_第3张图片
(3)下面是实现的主要代码,可作为一个插件,直接可用这里写代码片`
注:显示号码层为一个数组
cocoscreator typescript虚拟键盘的输入事件的简单实例_第4张图片

const { ccclass, property } = cc._decorator;

@ccclass
export default class JoinRoom extends cc.Component {
@property(cc.Label)
lableList: cc.Label[] = [];

roomIdString;
protected onLoad(): void {
    this.roomIdString = '';
}

public onButtonClick(event, customDate): void {
    console.log('custom date=' + customDate);
    //结束
    if (customDate === 'close') {
        this.node.destroy();
        //重输
    } else if (customDate === 'WeightLoss') {
        this.roomIdString = '';
        //删除
    } else if (customDate === 'delete') {
        this.roomIdString = this.roomIdString.substring(0, this.roomIdString.length - 1);
    } else {
        let string = '';
        string = this.roomIdString;
        string += customDate;
        console.log('string = ' + string);
        if (string.length > 6) {
            string = string.substring(0, String.length - 1);
        }
        this.roomIdString = string;
    }

}
public update(dt): void {
    for (let i = 0; i < this.lableList.length; i++) {
        this.lableList[i].string = '';
    }
    for (let i = 0; i < this.roomIdString.length; i++) {
        this.lableList[i].string = this.roomIdString[i];
    }


}

你可能感兴趣的:(cocoscreator typescript虚拟键盘的输入事件的简单实例)