tipBox.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // 提示框
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. label: cc.Label,
  6. tipLabel: cc.Label,
  7. },
  8. start() {
  9. this.tip = ['一次性大量消除可获得道具!', 'X2道具可以翻倍一次消除的分数', '炸弹道具可以消除全屏同色方块', '单个方块无法消除哦', '炸弹道具可以消除全屏同色方块', '仙女棒可以消除所有单个方块']
  10. this.otherTip = [
  11. '长风破浪会有时,直挂云帆济沧海',
  12. '黄沙百战穿金甲,不破楼兰终不还',
  13. '纸上得来终觉浅,绝知此事要躬行',
  14. '君子坦荡荡,小人长戚戚',
  15. '穷则独善其身,达则兼济天下',
  16. '盛年不重来,一日难再晨',
  17. '人生若只如初见,何事秋风悲画扇',
  18. '行到水穷处,坐看云起时',
  19. '天生我材必有用,千金散尽还复来',
  20. '大鹏一日同风起,扶摇直上九万里',
  21. '遥望齐州九点烟,一泓海水杯中泻',
  22. '人世几回伤往事,山形依旧枕寒流',
  23. '但使龙城飞将在,不教胡马度阴山',
  24. '十年一觉扬州梦,赢得青楼薄幸名',
  25. '沧海月明珠有泪,蓝田日暖玉生烟',
  26. '世间无限丹青手,一片伤心画不成',
  27. '男儿何不带吴钩,收取关山五十州',
  28. '苟利国家生死以,岂因祸福避趋之',
  29. '夜阑卧听风吹雨,铁马冰河入梦来',
  30. '人生自古谁无死?留取丹心照汗青'
  31. ]
  32. },
  33. onLoad() {
  34. setInterval(() => {
  35. this.tipLabel.string = this.tip ? ('tip:' + this.tip[Math.floor(Math.random() * this.tip.length)]) : ''
  36. }, 10000)
  37. },
  38. init(s, type) { //传type是道具触发 不传是随机触发
  39. this._score = s
  40. if (type > 0) {
  41. this.label.string = this.tip[type]
  42. } else {
  43. this.label.string = this.otherTip[Math.floor(Math.random() * this.otherTip.length)]
  44. }
  45. this.openTipBox()
  46. if (this.gapTimer) {
  47. clearInterval(this.gapTimer)
  48. }
  49. this.gapTimer = setInterval(() => {
  50. this.init(this._score, -1)
  51. }, 5000)
  52. },
  53. openTipBox() {
  54. if (!this.isOpen) {
  55. // 动画 动画回掉
  56. let action = cc.scaleTo(0.3, 1).easing(cc.easeBackOut(2.0))
  57. let sq = cc.sequence(action, cc.callFunc(() => {
  58. this.isOpen = true
  59. }))
  60. this.node.runAction(sq)
  61. }
  62. if (this.closeTimer) {
  63. clearTimeout(this.closeTimer)
  64. }
  65. this.closeTimer = setTimeout(() => {
  66. this.closeTioBox()
  67. }, 4000)
  68. },
  69. closeTioBox() {
  70. let action = cc.scaleTo(0.3, 0)
  71. let sq = cc.sequence(action, cc.callFunc(() => {
  72. this.isOpen = false
  73. }))
  74. this.node.runAction(sq)
  75. // if (this.openTimer) {
  76. // clearTimeout(this.closeTimer)
  77. // }
  78. //this.openTimer = setTimeout(this.init(this._score, null), this._score.level * 2000)
  79. },
  80. // update (dt) {},
  81. });