TweenCast.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const { ccclass, property } = cc._decorator;
  2. /**
  3. * 世界公告 滚动播放
  4. * @author 邹勇
  5. */
  6. @ccclass
  7. export default class TweenCast extends cc.Component {
  8. @property({ type: cc.RichText, displayName: "公告内容" })
  9. private rich_text: cc.RichText = null;
  10. @property({ displayName: "显示时间" })
  11. private display_time: number = 5;
  12. @property({ displayName: "进出速度" })
  13. private move_speed: number = 3;
  14. @property({ displayName: "等待时间" })
  15. private wait_time: number = 10;
  16. private names: string[] = ["拒绝寂寞", "孽緣", "祗為与妳相爱", "羙男", "浅蓝", "腊笔小东", "卡布奇诺", "苊狠幸福", "埋葬回忆", "早已该放手", "白兎",
  17. "豿疍疍", "宿命", "渗透的葬礼", "全都是虚假", "俄侑伱-直", "隱裑", "你不配我", "非主流网名", "剧终", "如果沵走了", "續雪", "默默然", "大白痴", "衮开",
  18. "越长大越不安", "寶疍疍", "爱笑的眼睛", "暧昧", "午夜", "我继续坚强", "冷温柔", "蹲在脚落", "喲妞你赞", "满足沵", "泪流", "听风在唱歌", "假装", "海岸线丶",
  19. "流年换ノ", "细数惭愧", "寂寞别说爱╮", "疯男人", "Darling", "伤狠痛", "留的住我不要", "静静的思念", "涐愿化作飞蛾", "欲", "提苏米拉", "夜凄凉",
  20. "一种矜持", "哼,涐呸", "贪婪", "一败涂地", "美如此多娇", "暧昧已落幕", "地平线"];
  21. private moneys: number[] = [0.5, 0.8, 1.0, 2, 5, 10, 20, 100];
  22. private weights: number[] = [40, 20, 10, 10, 10, 5, 3, 2];
  23. /**
  24. * 随机生成一个世界公告
  25. */
  26. private getContent(): string {
  27. let len = this.names.length;
  28. let i = Math.floor(mk.math.random(0, len, false));
  29. let name = this.names[i];
  30. len = this.moneys.length;
  31. i = mk.math.randomByWeight(this.weights, 100, false);
  32. let money = this.moneys[i];
  33. return `<outline color=#000000 width=1><color=#19F7FF>${name}</color>成功提现了<color=#FCE300>${money}元</color></outline>`;
  34. }
  35. onLoad() {
  36. if (gData.gameData.funOpenData['6'] == '1') {
  37. this.node.active = true
  38. this.play();
  39. }
  40. else {
  41. this.node.active = false
  42. }
  43. }
  44. private play() {
  45. this.reset();
  46. cc.tween(this.node)
  47. .delay(this.wait_time)
  48. .call(this.rickPlay.bind(this)).start();
  49. }
  50. private rickPlay() {
  51. this.node.active = true;
  52. cc.tween(this.rich_text.node)
  53. .to(this.move_speed, { x: 16 })
  54. .delay(this.display_time)
  55. .to(this.move_speed, { x: -450 })
  56. .call(this.play.bind(this)).start();
  57. }
  58. private reset() {
  59. this.node.active = false;
  60. this.rich_text.node.x = 450;
  61. this.rich_text.string = this.getContent();
  62. }
  63. }