JoinRoom.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. spriteFrame: [cc.SpriteFrame], // 假设这里已经包含了6个数字对应的SpriteFrame
  5. spritearr: [cc.Sprite] // 这里应该是6个Sprite组件
  6. },
  7. ctor: function () {
  8. this.m_numInidex = 0;
  9. this.m_numLabArr = [];
  10. this.m_numArr = '';
  11. },
  12. OnBtClickNum: function (Tag, Data) {
  13. cc.gSoundRes.PlaySound('Button');
  14. if (this.m_JoinNum = null) return;
  15. if (Data === 'Reset') { // 重置
  16. this.m_JoinNum = null;
  17. this.m_numArr = '';
  18. this.m_numInidex = 0;
  19. for (let i = 0; i < 6; i++) {
  20. this.m_numLabArr[i].spriteFrame = null; // 清空图片
  21. }
  22. } else if (Data === 'Del') { // 删除
  23. if (this.m_numArr.length) {
  24. this.m_numArr = this.m_numArr.slice(0, this.m_numArr.length - 1);
  25. this.m_numLabArr[--this.m_numInidex].spriteFrame = null; // 清空图片
  26. }
  27. } else { // 0-9
  28. this.m_numArr += Data;
  29. const numSpriteFrame = this.spriteFrame[parseInt(Data)]; // 获取对应的SpriteFrame
  30. if (numSpriteFrame) { // 检查是否获取到有效的SpriteFrame
  31. this.m_numLabArr[this.m_numInidex++].spriteFrame = numSpriteFrame;
  32. }
  33. }
  34. // 6位完成
  35. if (this.m_numArr.length >= 6) {
  36. this.m_JoinNum = parseInt(this.m_numArr);
  37. this.OnEnterRoom();
  38. this.m_numArr = '';
  39. this.m_numInidex = 0;
  40. for (let i = 0; i < 6; i++) {
  41. this.m_numLabArr[i].spriteFrame = null; // 清空图片
  42. }
  43. }
  44. },
  45. OnEnterRoom: function () {
  46. this.unschedule(this.OnEnterRoom);
  47. if (this.m_Hook) this.m_Hook.OnQueryRoom(this.m_JoinNum, 0);
  48. this.HideView();
  49. this.m_JoinNum = 0;
  50. },
  51. OnShowView: function () {
  52. for (let i = 0; i < 6; i++) {
  53. this.m_numLabArr.push(this.$(`TextBG/n${i}@Sprite`)); // 修改为Sprite组件
  54. this.m_numLabArr[i].spriteFrame = null; // 初始化为空
  55. }
  56. },
  57. OnEditInput: function () {
  58. this.OnBtClickNum(null, this.m_EdNum.string);
  59. },
  60. });