ColorRibbon.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { _decorator, Component, Node, Animation, Sprite, SpriteFrame, tween, Vec3 } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('ColorRibbon')
  5. export class ColorRibbon extends Component {
  6. @property({ tooltip: "旋转动画", type: Node }) public turnAnim: Node;//彩带旋转动画
  7. @property({ tooltip: "透明度显示动画", type: Node }) public showAnim: Node;//彩带透明度动画
  8. start() {
  9. this.initAnim();
  10. }
  11. public async initAnim() {
  12. let _turnAnim = this.turnAnim.getComponent(Animation);
  13. _turnAnim.getState("colorRibbonTurn").speed = Math.random();
  14. _turnAnim.getState("colorRibbonTurn").wrapMode = Math.random() < 0.5 ? 54 : 1;
  15. // this.turnAnim.getComponent(Animation).play();
  16. _turnAnim.play();
  17. let _showAnim = this.showAnim.getComponent(Animation);
  18. _showAnim.getState("colorRibbonShow").speed = 3 * Math.random();
  19. let _moveAnim = this.getComponent(Animation);
  20. _moveAnim.getState("colorRibbonMove").speed = Math.random() * 0.5 + 0.5;
  21. // this.getComponent(Animation).play();
  22. _moveAnim.play();
  23. let _type = Math.floor(Math.random() * 6) + 1;
  24. this.showAnim.getComponent(Sprite).spriteFrame =
  25. await ResourcesUtils.load<SpriteFrame>("Images/colorRibbon/彩带" + _type + "/spriteFrame", SpriteFrame, this.node);
  26. let endX = (Math.random() * 300) * (Math.random() - Math.random());
  27. let t = tween(this.turnAnim);
  28. t.to(3.5, { position: new Vec3(endX, 0, 0) }).start();
  29. if (_type == 3 || _type == 2) {
  30. this.showAnim.scale = new Vec3(0.5, 0.5);
  31. }
  32. }
  33. public removeThis() {
  34. this.node.destroy();
  35. }
  36. }