这种输入房号怎么弄

很好做啊,和做计算器几乎一样!

同问~~~

用字符串变量存储啊,界面上就单纯显示那个变量的内容,就比较简单

1赞

12个按钮 分别绑定12个按钮事件

用6个文本框

当6个文本框全部都不为空的时候传出去

删除和输入要自己写一些逻辑

1赞

也可以用1个文本框的咸鱼法
让文本框靠右对齐 看着你的字体大小给宽度

cc.Class({
    extends: cc.Component,

    properties: {
       ha:cc.Label
    },

    onLoad: function () {

    },

    a0:function(){
        this.test("    0");
    },
    a1:function(){
        this.test("    1");
    },
    a2:function(){
        this.test("    2");
    },
    a3:function(){
        this.test("    3");
    },
    a4:function(){
        this.test("    4");
    },
    a5:function(){
        this.test("    5");
    },
    a6:function(){
        this.test("    6");
    },
    a7:function(){
        this.test("    7");
    },
    a8:function(){
        this.test("    8");
    },
    a9:function(){
        this.test("    9");
    },
    re:function(){
        cc.log(1);
        this.ha.string ="";
    },  
    del:function(){
        this.ha.string = this.ha.string.substring(0,this.ha.string.length - 5);
    },

    test:function(str){
        this.ha.string += str;
        if(this.ha.string.length >25) {
            this.next();
            return;
        }
    },

    next:function(){
        cc.log("进游戏房间,然后清空");
        this.ha.string ="";
    },
});

这个是咸鱼写法 可能对屏幕适配产生问题

1赞

数组存起来。右边的下标对应数组的index就好了

给你参考

        const {ccclass, property} = cc._decorator;

	@ccclass
	export default class RoomJoinController extends cc.Component {
		@property([cc.Label]) private numLab: cc.Label[] = []; // 显示房间号的六个Label框

		private _index: number = 0;  // 记录label框数组的下标
		private _roomIdNum: string = ""; // 记录roomId

		protected onLoad() {
			if (!cc.sys.isNative) {
				cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onSystemKeyDown, this);
			}
		}

		private onSystemKeyDown(event: cc.Event.EventKeyboard) {
			let code = event.keyCode;
			if (code === cc.macro.KEY[0] || code === cc.macro.KEY.num0) {
				this.onClickZero();
			} else if (code === cc.macro.KEY[1] || code === cc.macro.KEY.num1) {
				this.onClickOne();
			} else if (code === cc.macro.KEY[2] || code === cc.macro.KEY.num2) {
				this.onClickTwo();
			} else if (code === cc.macro.KEY[3] || code === cc.macro.KEY.num3) {
				this.onClickThree();
			} else if (code === cc.macro.KEY[4] || code === cc.macro.KEY.num4) {
				this.onClickFour();
			} else if (code === cc.macro.KEY[5] || code === cc.macro.KEY.num5) {
				this.onClickFive();
			} else if (code === cc.macro.KEY[6] || code === cc.macro.KEY.num6) {
				this.onClickSix();
			} else if (code === cc.macro.KEY[7] || code === cc.macro.KEY.num7) {
				this.onClickSeven();
			} else if (code === cc.macro.KEY[8] || code === cc.macro.KEY.num8) {
				this.onClickEight();
			} else if (code === cc.macro.KEY[9] || code === cc.macro.KEY.num9) {
				this.onClickNine();
			}
		}

		private onClickZero() {
			this.onClickNum("0");
		}

		private onClickOne() {
			this.onClickNum("1");
		}

		private onClickTwo() {
			this.onClickNum("2");
		}

		private onClickThree() {
			this.onClickNum("3");
		}

		private onClickFour() {
			this.onClickNum("4");
		}

		private onClickFive() {
			this.onClickNum("5");
		}

		private onClickSix() {
			this.onClickNum("6");
		}

		private onClickSeven() {
			this.onClickNum("7");
		}

		private onClickEight() {
			this.onClickNum("8");
		}

		private onClickNine() {
			this.onClickNum("9");
		}

		private onClickNum (num: string) {
			this.numLab[this._index].string = num;
			this._index++;
			this._roomIdNum += num;
			if (this._index === 6) {
				let roomid = this._roomIdNum;
				this.doJoinRoom(parseInt(roomid));
			}
		}

		protected onClickReset() {
			for (let ele of this.numLab) {
				ele.string = "";
			}
			this._index = 0;
			this._roomIdNum = "";
		}

		protected onClickDelete() {
			if (this._index !== 0) {
				this.numLab[this._index].string = "";
				this._index--;
				this._roomIdNum = this._roomIdNum.substr(0, this._roomIdNum.length - 1);

			}
		}

		private doJoinRoom(roomId: number) {
			//
		}
	}
1赞