CardCtrl.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //间距定义
  2. var DEF_X_DISTANCE = 64; //默认间距
  3. //扑克结构
  4. var tagCardItem = cc.Class({
  5. ctor :function () {
  6. this.bShoot = false; //弹起标志 setCardShoot
  7. this.card = null; //扑克数据
  8. }
  9. });
  10. cc.Class({
  11. extends: cc.BaseClass,
  12. properties: {
  13. m_cardPre:cc.Prefab
  14. },
  15. ctor :function () {
  16. //扑克数据
  17. this.m_cbCardCount = 0; //扑克数目
  18. this.m_MaxCnt = 5;
  19. this.m_scale = 1;
  20. this.m_nXDistance = DEF_X_DISTANCE;
  21. this.m_AnchorMode = 0.5;
  22. this.m_CardNum = 0;
  23. },
  24. Init :function() {
  25. if(this.m_layoutCtrl == null){
  26. this.m_layoutCtrl = this.node.getComponent(cc.Layout);
  27. this.m_CardItemArray = new Array();
  28. for(var i=0;i<this.m_MaxCnt;i++) {
  29. this.m_CardItemArray[i] = new tagCardItem();
  30. }
  31. }
  32. },
  33. getCardPos :function(index){
  34. return this.m_CardItemArray[index].card.node.getPosition();
  35. },
  36. SetCardData:function (cbCardData, cbCardCount){
  37. this.Init();
  38. //效验参数
  39. if (cbCardCount > this.m_MaxCnt ) return false;
  40. //扑克数目
  41. this.m_cbCardCount = cbCardCount;
  42. //设置扑克
  43. for (var i = 0; i < this.m_cbCardCount; i++) {
  44. this.m_CardItemArray[i].bShoot = false;
  45. if( this.m_CardItemArray[i].card == null ){
  46. this.m_CardItemArray[i].card = cc.instantiate(this.m_cardPre).getComponent('CardPrefab');
  47. // this.m_CardItemArray[i].card.m_bValueHide = true;
  48. this.node.addChild(this.m_CardItemArray[i].card.node);
  49. }
  50. this.m_CardItemArray[i].card.node.active = true;
  51. //if(cbCardData[i] == null) cbCardData[i] = 0;
  52. this.m_CardItemArray[i].card.SetData(cbCardData[i]);
  53. }
  54. this.DrawCard();
  55. return true;
  56. },
  57. //绘画扑克
  58. DrawCard:function () {
  59. this.m_layoutCtrl.spacingX = this.m_nXDistance - CARD_WIGTH;//*this.m_scale
  60. this.node.anchorX = this.m_AnchorMode;
  61. for (var i=0; i < this.m_MaxCnt; i++){
  62. if(i < this.m_cbCardCount){
  63. var cardData = this.m_CardItemArray[i].card.GetData();
  64. this.m_CardItemArray[i].card.SetData(cardData);
  65. }else{
  66. this.m_CardItemArray[i].bShoot = false;
  67. if( this.m_CardItemArray[i].card != null )
  68. this.m_CardItemArray[i].card.node.active = false;
  69. }
  70. }
  71. },
  72. //获取扑克
  73. GetCardData:function (cbCardData, cbBufferCount){
  74. //效验参数
  75. if (cbBufferCount<this.m_cbCardCount) return 0;
  76. //拷贝扑克
  77. for (var i=0;i<this.m_cbCardCount;i++){
  78. cbCardData[i]=this.m_CardItemArray[i].card.GetData();
  79. }
  80. return this.m_cbCardCount;
  81. },
  82. //扑克数目
  83. GetCardCount:function () { return this.m_cbCardCount; },
  84. //基准位置
  85. SetBenchmarkPos:function (nXPos, nYPos, Mode){
  86. this.node.setPosition(nXPos,nYPos);
  87. this.m_AnchorMode = 0.5*(Mode - 1)
  88. },
  89. //基准位置
  90. SetScale:function (scale){
  91. this.m_scale = scale;
  92. this.node.scale = scale;
  93. },
  94. //设置距离
  95. SetCardDistance:function (nXDistance) {
  96. this.m_nXDistance = CARD_WIGTH + nXDistance;
  97. },
  98. });