TileBlock.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. remove: boolean = false
  11. private _type: number;
  12. row: number
  13. col: number
  14. layer: number
  15. aniObj = { c: 0 }
  16. public get type(): number {
  17. return this._type;
  18. }
  19. public set type(value: number) {
  20. this._type = value;
  21. cc.resources.load("ares_bndl/icons/"+value,cc.Texture2D,(err, texture: cc.Texture2D) => {
  22. let sp = new cc.SpriteFrame(texture)
  23. this.sp_icon.spriteFrame = sp
  24. })
  25. }
  26. start() {
  27. }
  28. private _dark: boolean = false;
  29. public get dark(): boolean {
  30. return this._dark;
  31. }
  32. public set dark(value: boolean) {
  33. this._dark = value;
  34. }
  35. setDark(value: boolean, ani: boolean = false) {
  36. if (this._dark != value) {
  37. this._dark = value
  38. if (ani) {
  39. let start = 80
  40. let end = 255
  41. if (value) {
  42. start = 255
  43. end = 80
  44. }
  45. this.aniObj.c = start
  46. cc.Tween.stopAllByTarget(this.aniObj)
  47. cc.tween(this.aniObj).to(0.5, { c: end }, {
  48. progress: (start, end, current, radio) => {
  49. let tempColor = start + (end - start) * radio
  50. this.sp_icon.node.color = cc.color(tempColor, tempColor, tempColor)
  51. this.tileBg.color = cc.color(tempColor, tempColor, tempColor)
  52. }
  53. }).start()
  54. } else {
  55. let grayse = 80
  56. this.sp_icon.node.color = value ? cc.color(grayse, grayse, grayse) : cc.color(255, 255, 255)
  57. this.tileBg.color = value ? cc.color(grayse, grayse, grayse) : cc.color(255, 255, 255)
  58. }
  59. }
  60. }
  61. recycle(ani: boolean = false) {
  62. this.remove = false
  63. this._dark = false
  64. cc.Tween.stopAllByTarget(this.aniObj)
  65. cc.Tween.stopAllByTarget(this.node)
  66. this.sp_icon.node.color = cc.color(255, 255, 255)
  67. this.tileBg.color = cc.color(255, 255, 255)
  68. if (ani) {
  69. cc.tween(this.node).delay(0.06).to(0.2, { scale: 0 }).call(() => {
  70. game_core.pool.recover('TileBlock', this.node)
  71. }).start()
  72. } else {
  73. game_core.pool.recover('TileBlock', this.node)
  74. }
  75. }
  76. // update (dt) {}
  77. }