| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- cc.Class({
- extends: cc.BaseClass,
- properties: {
- spriteFrame: [cc.SpriteFrame], // 假设这里已经包含了6个数字对应的SpriteFrame
- spritearr: [cc.Sprite] // 这里应该是6个Sprite组件
- },
- ctor: function () {
- this.m_numInidex = 0;
- this.m_numLabArr = [];
- this.m_numArr = '';
- },
-
-
-
- OnBtClickNum: function (Tag, Data) {
- cc.gSoundRes.PlaySound('Button');
- if (this.m_JoinNum = null) return;
- if (Data === 'Reset') { // 重置
- this.m_JoinNum = null;
- this.m_numArr = '';
- this.m_numInidex = 0;
- for (let i = 0; i < 6; i++) {
- this.m_numLabArr[i].spriteFrame = null; // 清空图片
- }
- } else if (Data === 'Del') { // 删除
- if (this.m_numArr.length) {
- this.m_numArr = this.m_numArr.slice(0, this.m_numArr.length - 1);
- this.m_numLabArr[--this.m_numInidex].spriteFrame = null; // 清空图片
- }
- } else { // 0-9
- this.m_numArr += Data;
- const numSpriteFrame = this.spriteFrame[parseInt(Data)]; // 获取对应的SpriteFrame
- if (numSpriteFrame) { // 检查是否获取到有效的SpriteFrame
- this.m_numLabArr[this.m_numInidex++].spriteFrame = numSpriteFrame;
- }
- }
- // 6位完成
- if (this.m_numArr.length >= 6) {
- this.m_JoinNum = parseInt(this.m_numArr);
- this.OnEnterRoom();
- this.m_numArr = '';
- this.m_numInidex = 0;
- for (let i = 0; i < 6; i++) {
- this.m_numLabArr[i].spriteFrame = null; // 清空图片
- }
- }
- },
- OnEnterRoom: function () {
- this.unschedule(this.OnEnterRoom);
- if (this.m_Hook) this.m_Hook.OnQueryRoom(this.m_JoinNum, 0);
- this.HideView();
- this.m_JoinNum = 0;
- },
- OnShowView: function () {
- for (let i = 0; i < 6; i++) {
- this.m_numLabArr.push(this.$(`TextBG/n${i}@Sprite`)); // 修改为Sprite组件
- this.m_numLabArr[i].spriteFrame = null; // 初始化为空
- }
- },
- OnEditInput: function () {
- this.OnBtClickNum(null, this.m_EdNum.string);
- },
- });
|