TipSprite.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. //建筑底下碰撞区域
  5. Red: {
  6. // ATTRIBUTES:
  7. default: null, // The default value will be used only when the component attaching
  8. // to a node for the first time
  9. type: cc.SpriteFrame, // optional, default is typeof default
  10. serializable: true, // optional, default is true
  11. },
  12. Green: {
  13. // ATTRIBUTES:
  14. default: null, // The default value will be used only when the component attaching
  15. // to a node for the first time
  16. type: cc.SpriteFrame, // optional, default is typeof default
  17. serializable: true, // optional, default is true
  18. },
  19. Tip: cc.Sprite,
  20. //如果是数组
  21. isChildenArray: false,
  22. //建筑对周围的影响力
  23. effectYellow: {
  24. // ATTRIBUTES:
  25. default: null,
  26. type: cc.SpriteFrame,
  27. serializable: true,
  28. },
  29. effectGreen: {
  30. // ATTRIBUTES:
  31. default: null, // The default value will be used only when the component attaching
  32. // to a node for the first time
  33. type: cc.SpriteFrame, // optional, default is typeof default
  34. serializable: true, // optional, default is true
  35. },
  36. },
  37. //设置红色提示
  38. onSetRedSpriteFrame(_opacity) {
  39. if (_opacity)
  40. this.Tip.node.opacity = _opacity;
  41. if (this.isChildenArray) {
  42. let TipArray = this.node.children;
  43. // cc.log(TipArray)
  44. let length = TipArray.length;
  45. for (let i = 0; i < length; i++) {
  46. TipArray[i].getComponent(cc.Sprite).spriteFrame = this.Red;
  47. }
  48. } else {
  49. this.Tip.spriteFrame = this.Red;
  50. }
  51. },
  52. //重新设置图片
  53. onReset() {
  54. this.Tip.node.scale = 1;
  55. // this.Tip.node.color.setA(1);
  56. this.Tip.node.opacity = 230;
  57. if (this.isChildenArray) {
  58. let TipArray = this.node.children;
  59. let length = TipArray.length;
  60. for (let i = 0; i < length; i++) {
  61. TipArray[i].getComponent(cc.Sprite).spriteFrame = this.Green;
  62. }
  63. } else {
  64. this.Tip.spriteFrame = this.Green;
  65. }
  66. },
  67. //设置影响力黄色
  68. onSetEffectYellowSpriteFrame() {
  69. this.Tip.spriteFrame = this.effectYellow;
  70. this.Tip.node.scale = 0.8;
  71. // this.Tip.node.color.setA(0.5);
  72. this.Tip.node.opacity = 200;
  73. },
  74. //设置影响力 绿色
  75. onSetEffectGreenSpriteFrame() {
  76. this.Tip.spriteFrame = this.effectGreen;
  77. this.Tip.node.scale = 0.8;
  78. // this.Tip.node.color.setA(0.5);
  79. this.Tip.node.opacity = 200;
  80. },
  81. });