StarAnim.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, Component, Node, Animation, v3, SpriteFrame, Sprite } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('StarAnim')
  5. export class StarAnim extends Component {
  6. @property({ tooltip: '星星', type: Node })
  7. public star: Node;
  8. start() {
  9. }
  10. /**
  11. * 特效数据重置
  12. * @param wrapMode 播放模式,两种模式正循环和反循环(2:正循环,38:反循环)
  13. * @param setTime 设置播放时间(0~3)
  14. * @param x 特效坐标点x
  15. * @param y 特效坐标点y
  16. * @param scale 特效缩放
  17. * @param image 星星特效图片名称(必须是"Resources/star"文件夹下面的图片资源),使用默认资源可不填写
  18. */
  19. public async setData(wrapMode: number, setTime: number, x: number, y: number, scale: number, image?: string) {
  20. if (image) {
  21. let img: SpriteFrame = await ResourcesUtils.load("Images/star/" + image + "/spriteFrame", SpriteFrame, this.node);
  22. this.star.getComponent(Sprite).spriteFrame = img;
  23. }
  24. let tempAnimation = this.node.getComponent(Animation);
  25. tempAnimation.play('starTurn');
  26. let tempAnimation0 = this.star.getComponent(Animation);
  27. tempAnimation0.play('starScale');
  28. tempAnimation0.getState("starScale").setTime(setTime);
  29. tempAnimation.getState("starTurn").wrapMode = wrapMode;
  30. this.node.position = v3(x, y);
  31. this.node.setScale(v3(scale, scale));
  32. }
  33. public destroyNode() {
  34. this.node.destroy();
  35. }
  36. }