CachetaCard.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. var GameProtocol = require("CachetaGameProtocol");
  2. import ScenceManager from 'HNScenceManager';
  3. cc.Class({
  4. extends: cc.Component,
  5. editor: {
  6. menu: 'Game/Cacheta/Card'
  7. },
  8. properties: {
  9. atlasCards:
  10. {
  11. default:null,
  12. type:cc.SpriteAtlas
  13. },
  14. m_nCardId:0,
  15. Joker:false, //是否百搭
  16. },
  17. setId:function(id,MagicIdArr,picked) {
  18. this.m_nCardId = id;
  19. this.Joker = false;
  20. // let jsGame = ScenceManager.Instance().getGameComponent();
  21. // cc.log(typeof MagicIdArr)
  22. if(MagicIdArr == null || MagicIdArr == undefined) {
  23. MagicIdArr = [];
  24. }
  25. if (this.atlasCards) {
  26. var color = this.cardColor() + 1;
  27. var num = this.cardNum();
  28. var sprName = "handmah_" + color + num;
  29. if (this.m_nCardId == 0) {
  30. sprName = "handmah_" + 0 + 0;
  31. }
  32. var frame = this.atlasCards.getSpriteFrame(sprName);
  33. // if(jsGame && jsGame.cardAtlas) {
  34. // frame = jsGame.cardAtlas.getSpriteFrame(sprName)
  35. // }
  36. if (frame == null) {
  37. }
  38. this.node.getComponent(cc.Sprite).spriteFrame = frame;
  39. if(this.m_nCardId == 0 || MagicIdArr.length == 0){
  40. this.node.getChildByName("MagicCard").active = false;
  41. }else{
  42. if(MagicIdArr[0] == id || MagicIdArr[1] == id){
  43. this.node.getChildByName("MagicCard").active = true;
  44. this.Joker = true;
  45. }else{
  46. this.node.getChildByName("MagicCard").active = false;
  47. }
  48. let pickNode = this.node.getChildByName("picked");
  49. if(pickNode){
  50. pickNode.active = (picked == 1);
  51. }
  52. }
  53. }
  54. },
  55. isJoker(){
  56. return this.Joker;
  57. },
  58. cardId:function () {
  59. return this.m_nCardId;
  60. },
  61. cardColor:function () {
  62. return ((this.m_nCardId>>4) & 0x0F);
  63. },
  64. cardNum:function () {
  65. return (this.m_nCardId & 0x0F);
  66. },
  67. getCardColor:function (CardId) {
  68. return ((CardId>>4) & 0x0F);
  69. },
  70. getCardNum:function (CardId) {
  71. return (CardId & 0x0F);
  72. },
  73. });