| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { _decorator, Component, Node, Animation, Sprite, SpriteFrame, tween, Vec3 } from 'cc';
- import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
- const { ccclass, property } = _decorator;
- @ccclass('ColorRibbon')
- export class ColorRibbon extends Component {
- @property({ tooltip: "旋转动画", type: Node }) public turnAnim: Node;//彩带旋转动画
- @property({ tooltip: "透明度显示动画", type: Node }) public showAnim: Node;//彩带透明度动画
- start() {
- this.initAnim();
- }
- public async initAnim() {
- let _turnAnim = this.turnAnim.getComponent(Animation);
- _turnAnim.getState("colorRibbonTurn").speed = Math.random();
- _turnAnim.getState("colorRibbonTurn").wrapMode = Math.random() < 0.5 ? 54 : 1;
- // this.turnAnim.getComponent(Animation).play();
- _turnAnim.play();
- let _showAnim = this.showAnim.getComponent(Animation);
- _showAnim.getState("colorRibbonShow").speed = 3 * Math.random();
- let _moveAnim = this.getComponent(Animation);
- _moveAnim.getState("colorRibbonMove").speed = Math.random() * 0.5 + 0.5;
- // this.getComponent(Animation).play();
- _moveAnim.play();
- let _type = Math.floor(Math.random() * 6) + 1;
- this.showAnim.getComponent(Sprite).spriteFrame =
- await ResourcesUtils.load<SpriteFrame>("Images/colorRibbon/彩带" + _type + "/spriteFrame", SpriteFrame, this.node);
- let endX = (Math.random() * 300) * (Math.random() - Math.random());
- let t = tween(this.turnAnim);
- t.to(3.5, { position: new Vec3(endX, 0, 0) }).start();
- if (_type == 3 || _type == 2) {
- this.showAnim.scale = new Vec3(0.5, 0.5);
- }
- }
- public removeThis() {
- this.node.destroy();
- }
- }
|