WeaveControl.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. m_WeaveParent:[cc.Node],
  5. m_WeavePrefab:cc.Prefab,
  6. m_WeaveItem:cc.Prefab,
  7. },
  8. ctor:function(){
  9. this.m_WeaveArray = new Array();
  10. this.m_wCardCount = 0;
  11. },
  12. Init: function(state) {
  13. var buildCardCount = 0; // 初始化计数器
  14. for (var i = 0; i < 5; i++) {
  15. // 如果当前位置的WeaveArray为空,则实例化一个新的WeavePrefab对象
  16. if (this.m_WeaveArray[i] == null) {
  17. var Weave = cc.instantiate(this.m_WeavePrefab); // 实例化预制体
  18. Weave.active = false; // 初始化时设置为不活跃状态
  19. this.m_WeaveArray[i] = Weave.getComponent('WeaveItem'); // 获取WeaveItem组件并存入数组
  20. this.m_WeaveParent[i].addChild(Weave); // 将新实例添加到对应位置的父节点
  21. // 调用WeaveItem组件的BuildCard方法,构建牌
  22. this.m_WeaveArray[i].BuildCard(state, this.m_WeaveItem);
  23. buildCardCount++; // 计数器加1
  24. }
  25. }
  26. },
  27. SetWeaveData:function(index,cbCardData,wCardCount){
  28. this.m_WeaveArray[index].node.active = true;
  29. this.m_WeaveArray[index].SetWeaveData(cbCardData,wCardCount);
  30. },
  31. SetWeaveState:function(index,State, bEnd){
  32. this.m_WeaveArray[index].SetWeaveState(State, bEnd);
  33. },
  34. ResetData:function(){
  35. for (var i = 0; i < this.m_WeaveArray.length; i++) {
  36. this.m_WeaveArray[i].node.active = false;
  37. }
  38. },
  39. // update (dt) {},
  40. });