CardPrefab.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. var DEF_SHOOT_DISTANCE = 20; //默认间距
  2. cc.Class({
  3. extends: cc.BaseClass,
  4. properties: {
  5. m_atlas:cc.SpriteAtlas,
  6. },
  7. ctor:function (){
  8. this.m_colorArr = new Array(cc.color(255,255,255),cc.color(200,255,255));
  9. this.m_cbCardData = 0xff;
  10. this.m_bValueHide = false;
  11. },
  12. InitCtrl:function (){
  13. if(this.m_CardSprite == null) this.m_CardSprite = this.$('Card@Sprite');
  14. if(this.m_NumSprite == null) this.m_NumSprite = this.$('Card/CN@Sprite');
  15. if(this.m_SFlowerSprite == null) this.m_SFlowerSprite = this.$('Card/SF@Sprite');
  16. if(this.m_BFlowerSprite == null) this.m_BFlowerSprite = this.$('Card/BF@Sprite');
  17. if(this.m_SFlowerSprite2 == null) this.m_SFlowerSprite2 = this.$('Card/SF2@Sprite');
  18. if(this.m_NumSprite2 == null) this.m_NumSprite2 = this.$('Card/CN2@Sprite');
  19. },
  20. SetData:function (cbCardData){
  21. this.InitCtrl();
  22. this.node.active = true;
  23. if ( this.m_CardSprite) {
  24. this.m_CardSprite.node.active = true;
  25. }
  26. this.HideCardSp();
  27. this.m_cbCardData = cbCardData;
  28. if( cbCardData==0 || cbCardData==undefined){ //牌背
  29. this.m_cbCardData = 0xff; //牌背
  30. if(this.m_bValueHide){
  31. if ( this.m_CardSprite) {
  32. this.m_CardSprite.node.active = false;
  33. }
  34. return;
  35. }
  36. }
  37. //牌背 大小王
  38. var color = this.GetColor(this.m_cbCardData);
  39. if(color >= 4){
  40. if ( this.m_CardSprite) {
  41. this.m_CardSprite.spriteFrame = this.m_atlas.getSpriteFrame(this.m_cbCardData);
  42. }
  43. return
  44. }
  45. var value = this.m_cbCardData&0xf;
  46. var colorStr = color%2==0?'r':'b';
  47. this.m_NumSprite.node.active = true;
  48. this.m_SFlowerSprite.node.active = true;
  49. this.m_BFlowerSprite.node.active = true;
  50. //白底
  51. if ( this.m_CardSprite ) this.m_CardSprite.spriteFrame = this.m_atlas.getSpriteFrame('BG');
  52. //牌值
  53. this.m_NumSprite.spriteFrame = this.m_atlas.getSpriteFrame(colorStr+value);
  54. if (this.m_NumSprite2) { //镜像数字
  55. this.m_NumSprite2.node.active = true;
  56. this.m_NumSprite2.spriteFrame = this.m_atlas.getSpriteFrame(colorStr+value);
  57. }
  58. //小花
  59. this.m_SFlowerSprite.spriteFrame = this.m_atlas.getSpriteFrame('fs'+color);
  60. if (this.m_SFlowerSprite2) { //镜像小牌花
  61. this.m_SFlowerSprite2.node.active = true;
  62. this.m_SFlowerSprite2.spriteFrame = this.m_atlas.getSpriteFrame('fs'+color);
  63. }
  64. //大花
  65. this.m_BFlowerSprite.spriteFrame = this.m_atlas.getSpriteFrame('f'+(value<11?color:colorStr+value));
  66. },
  67. HideCardSp:function (){
  68. this.InitCtrl();
  69. this.m_NumSprite.node.active = false;
  70. this.m_SFlowerSprite.node.active = false;
  71. this.m_BFlowerSprite.node.active = false;
  72. if (this.m_NumSprite2) this.m_NumSprite2.node.active = false;
  73. if (this.m_SFlowerSprite2) this.m_SFlowerSprite2.node.active = false;
  74. },
  75. SetGiveUp:function(){
  76. this.InitCtrl();
  77. this.HideCardSp();
  78. this.m_CardSprite.spriteFrame = this.m_atlas.getSpriteFrame(256);
  79. },
  80. SetLose:function(){
  81. this.InitCtrl();
  82. this.HideCardSp();
  83. this.m_CardSprite.spriteFrame = this.m_atlas.getSpriteFrame(257);
  84. },
  85. GetData:function(){
  86. return this.m_cbCardData;
  87. },
  88. GetColor:function(CardData){
  89. return (CardData >> 4);
  90. },
  91. GetCardWidth :function(){
  92. this.InitCtrl();
  93. return this.m_CardSprite.node.getContentSize().width;
  94. },
  95. GetCardHeight:function () {
  96. this.InitCtrl();
  97. return this.m_CardSprite.node.getContentSize().height;
  98. },
  99. SetCardShoot:function (bShow) {
  100. this.InitCtrl();
  101. this.m_CardSprite.node.y=(bShow?DEF_SHOOT_DISTANCE:0);
  102. },
  103. SetBanker:function (bShow) {
  104. var NdBanker = this.$('Card/Banker');
  105. if(NdBanker) NdBanker.active = bShow;
  106. },
  107. SetSelect:function(bSelect){
  108. if ( this.m_CardSprite){
  109. this.m_CardSprite.node.color = this.m_colorArr[0];
  110. if(bSelect)this.m_CardSprite.node.color = this.m_colorArr[1];
  111. }
  112. },
  113. SetBlack:function(bBlack){
  114. this.$('Card/Dark').active = bBlack;
  115. },
  116. });