SendCardCtrl.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var actTime = 0.2;
  2. var delayTime = actTime/4;
  3. cc.Class({
  4. extends: cc.BaseClass,
  5. properties: {
  6. m_cardPrefab:cc.Prefab
  7. },
  8. ctor:function(){
  9. this.m_StartPos = new cc.v2(0,0);
  10. this.m_ActCardCount = 0;
  11. this.m_PosArr= null;
  12. this.m_CardScale = 0.54;
  13. },
  14. start :function() {
  15. this.m_NodePool = new cc.NodePool('CardTempPool');
  16. },
  17. GetCard :function(){
  18. var TempCard;
  19. if(this.m_NodePool.size()){
  20. TempCard = this.m_NodePool.get();
  21. }else{
  22. TempCard = cc.instantiate(this.m_cardPrefab);
  23. }
  24. TempCard.scale = this.m_CardScale;
  25. this.node.addChild(TempCard);
  26. TempCard.setPosition(this.ChangeCardPos(this.m_StartPos));
  27. var TempCtrl = TempCard.getComponent('CardPrefab');
  28. TempCtrl.SetData(0);
  29. TempCtrl.SetBanker(false);
  30. TempCard.getChildByName('Card').active = false;
  31. return TempCtrl;
  32. },
  33. //左下对其点换算中心对齐坐标
  34. ChangeCardPos:function(Pos){
  35. return cc.v2(Pos.x - CARD_WIGTH/2*this.m_CardScale, Pos.y - CARD_HEIGHT/2*this.m_CardScale);
  36. },
  37. //回收节点
  38. DelCard:function(node){
  39. node.parent = null;
  40. this.m_NodePool.put(node);
  41. },
  42. //基准位置
  43. SetBenchmarkPos:function (startPos, EndPosArr){
  44. this.m_StartPos = startPos;
  45. this.m_PosArr = EndPosArr;
  46. },
  47. PlaySendCard:function (cnt, start){
  48. for(var i=0;i<cnt;i++){
  49. for(var j=0;j<GameDef.GAME_PLAYER;j++){
  50. var viewID = (j+start)%GameDef.GAME_PLAYER;
  51. var TempCard = this.GetCard();
  52. this.SetNodeAct(TempCard.node, viewID, i);
  53. }
  54. }
  55. },
  56. PlaySendCard33301:function (cnt, start,cbPlayStatus){
  57. for(var i=0;i<cnt;i++){
  58. for(var j=0;j<2;j++){
  59. var viewID = (j+start)%2;
  60. if(!cbPlayStatus[viewID])continue;
  61. var TempCard = this.GetCard();
  62. this.SetNodeAct(TempCard.node, viewID, i);
  63. }
  64. }
  65. },
  66. SetNodeAct:function (node, viewID, index){
  67. this.m_ActCardCount++;
  68. var act = cc.sequence( cc.delayTime(this.m_ActCardCount*delayTime), cc.callFunc(this.ShowCardFunc, this, node) );
  69. var act2 = cc.sequence( act, cc.moveTo(actTime, this.ChangeCardPos(this.m_PosArr[viewID])));
  70. node.runAction(cc.sequence(act2, cc.callFunc(this.EndCallFunc, this, [this, viewID, index])));
  71. },
  72. ShowCardFunc:function (Tag, node ){
  73. node.getChildByName('Card').active = true;
  74. },
  75. //node: TempCard.node ; para = [this, viewID, index]
  76. EndCallFunc:function (node, para){
  77. cc.gSoundRes.PlaySound('SendCard');
  78. para[0].DelCard(node);
  79. para[0].m_ActCardCount--;
  80. para[0].m_Hook.m_GameClientEngine.OnMessageDispatchFinish(para[1], para[2], para[0].m_ActCardCount);
  81. },
  82. Isplaying:function(){
  83. return this.m_ActCardCount > 0;
  84. },
  85. // update (dt) {},
  86. });