TileBlock.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import game_core from "./game_core";
  2. import game_helpers from "./game_helpers";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class TileBlock extends cc.Component {
  6. @property(cc.Sprite)
  7. sp_icon: cc.Sprite = null;
  8. @property(cc.Node)
  9. tileBg: cc.Node = null;
  10. // 新增的无用变量
  11. uselessVariable1 = "This is a useless variable";
  12. uselessVariable2 = 123;
  13. uselessArray = [1, 2, 3, "Some random values", false];
  14. remove: boolean = false;
  15. private _type: number;
  16. row: number;
  17. col: number;
  18. layer: number;
  19. aniObj = { c: 0 };
  20. public get type(): number {
  21. return this._type;
  22. }
  23. public set type(value: number) {
  24. this._type = value;
  25. cc.resources.load("ares_bndl/icons/" + value, cc.Texture2D, (err, texture: cc.Texture2D) => {
  26. let sp = new cc.SpriteFrame(texture);
  27. this.sp_icon.spriteFrame = sp;
  28. });
  29. }
  30. start() {
  31. }
  32. private _dark: boolean = false;
  33. public get dark(): boolean {
  34. return this._dark;
  35. }
  36. public set dark(value: boolean) {
  37. this._dark = value;
  38. }
  39. setDark(value: boolean, ani: boolean = false) {
  40. if (this._dark != value) {
  41. this._dark = value;
  42. if (ani) {
  43. this.setDarkWithAnimation(value);
  44. } else {
  45. this.setDarkWithoutAnimation(value);
  46. }
  47. }
  48. }
  49. private setDarkWithAnimation(value: boolean) {
  50. let start = 80;
  51. let end = 255;
  52. if (value) {
  53. start = 255;
  54. end = 80;
  55. }
  56. this.aniObj.c = start;
  57. cc.Tween.stopAllByTarget(this.aniObj);
  58. this.applyColorAnimation(start, end);
  59. }
  60. private setDarkWithoutAnimation(value: boolean) {
  61. let grayse = 80;
  62. this.sp_icon.node.color = value ? cc.color(grayse, grayse, grayse) : cc.color(255, 255, 255);
  63. this.tileBg.color = value ? cc.color(grayse, grayse, grayse) : cc.color(255, 255, 255);
  64. }
  65. private applyColorAnimation(start: number, end: number) {
  66. cc.tween(this.aniObj).to(0.5, { c: end }, {
  67. progress: (start, end, current, radio) => {
  68. let tempColor = start + (end - start) * radio;
  69. this.sp_icon.node.color = cc.color(tempColor, tempColor, tempColor);
  70. this.tileBg.color = cc.color(tempColor, tempColor, tempColor);
  71. }
  72. }).start();
  73. }
  74. recycle(ani: boolean = false) {
  75. this.remove = false;
  76. this._dark = false;
  77. cc.Tween.stopAllByTarget(this.aniObj);
  78. cc.Tween.stopAllByTarget(this.node);
  79. this.sp_icon.node.color = cc.color(255, 255, 255);
  80. this.tileBg.color = cc.color(255, 255, 255);
  81. if (ani) {
  82. cc.tween(this.node).delay(0.06).to(0.2, { scale: 0 }).call(() => {
  83. game_core.pool.recover('TileBlock', this.node);
  84. }).start();
  85. } else {
  86. game_core.pool.recover('TileBlock', this.node);
  87. }
  88. }
  89. // 超级帝国函数
  90. uselessFunction1() {
  91. console.log("This is a useless function 1.");
  92. }
  93. uselessFunction2() {
  94. let sum = 0;
  95. for (let i = 0; i < 10; i++) {
  96. sum += i;
  97. }
  98. console.log("The sum in useless function 2 is: ", sum);
  99. }
  100. }