RotatingLightAnim.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator, Component, Node, Vec3, animation, Animation, SpriteFrame, Sprite, UITransform } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('RotatingLightAnim')
  5. export class RotatingLightAnim extends Component {
  6. public tempAnimation: Animation;
  7. public start() {
  8. }
  9. /**
  10. * @zh 旋转光效参数设置
  11. * @param width 宽度
  12. * @param height 高度
  13. * @param speed 动画播放速度
  14. * @param isZoom 是否需要播放缩放动画,true为需要
  15. * @param image 旋转光效图片名称(必须是"Resources/Images/rotatingLight"文件夹下面的图片资源),使用默认资源可不填写
  16. */
  17. public async set_Data(width: number, height: number, speed: number, isZoom: boolean, image?: string) {
  18. this.tempAnimation = this.node.getComponent(Animation);
  19. // this.node.setScale(scaleX, scaleY);
  20. this.node.getComponent(UITransform).width = width;
  21. this.node.getComponent(UITransform).height = height;
  22. this.tempAnimation.getState("rotatingLightEffect").speed = speed;
  23. this.tempAnimation.getState("rotatingLightEffect0").speed = speed;
  24. if (image) {
  25. let img: SpriteFrame = await ResourcesUtils.load("Images/rotatingLight/" + image + "/spriteFrame", SpriteFrame, this.node);
  26. this.node.getComponent(Sprite).spriteFrame = img;
  27. }
  28. if (isZoom) {
  29. this.tempAnimation.play("rotatingLightEffect");
  30. } else {
  31. this.test();
  32. }
  33. }
  34. public test() {
  35. this.tempAnimation.play("rotatingLightEffect0");
  36. }
  37. }