Card.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. atlasCards:
  5. {
  6. default:null,
  7. type:cc.SpriteAtlas
  8. },
  9. m_nCardId:0,
  10. },
  11. setId:function(id) {
  12. this.m_nCardId = id;
  13. if (this.atlasCards) {
  14. var color = this.cardColor() + 1;
  15. var num = this.cardNum();
  16. var sprName = "handmah_" + color + num;
  17. if (this.m_nCardId == 0) {
  18. sprName = "handmah_" + 0 + 0;
  19. }
  20. var frame = this.atlasCards.getSpriteFrame(sprName);
  21. if (frame == null) {
  22. }
  23. this.node.getComponent(cc.Sprite).spriteFrame = frame;
  24. }
  25. },
  26. cardId:function () {
  27. return this.m_nCardId;
  28. },
  29. cardColor:function () {
  30. return ((this.m_nCardId>>4) & 0x0F);
  31. },
  32. cardNum:function () {
  33. return (this.m_nCardId & 0x0F);
  34. },
  35. getCardColor:function (CardId) {
  36. return ((CardId>>4) & 0x0F);
  37. },
  38. getCardNum:function (CardId) {
  39. return (CardId & 0x0F);
  40. },
  41. });