SpinManager.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { SingleClass } from "./SingleClass";
  2. const { ccclass, property } = cc._decorator;
  3. export enum AnimType {
  4. Dog = 1,
  5. Daoju = 2,
  6. }
  7. @ccclass
  8. export default class SpinManager extends SingleClass {
  9. // public spSkeleton: sp.Skeleton = null;//动画
  10. // public currentAnimName: string = '';
  11. // 更换动画资源
  12. public ChangeSpineAnimation(node: cc.Node, path: string, animationName: string, isLoop: boolean, completeCallback: any = null, self: any = null, timeScale: number = 1){
  13. let spSkeleton = node.getComponent(sp.Skeleton);
  14. spSkeleton.loop = isLoop;
  15. spSkeleton.timeScale = timeScale;
  16. cc.assetManager.loadBundle("gameScene", (err,bundle)=>{
  17. bundle.load(path, sp.SkeletonData, function (err: Error, data: sp.SkeletonData) {
  18. if (err) {
  19. console.log("err", err);
  20. } else {
  21. spSkeleton.skeletonData = data;
  22. }
  23. });
  24. })
  25. }
  26. /**
  27. * 播放spin动画
  28. * @param animationName 动画名称
  29. * @param completeCallback 播放回调
  30. * @param isLoop 是否循环
  31. */
  32. public PlaySpinAnimation(node: cc.Node, animationName: string, isLoop: boolean, completeCallback: any = null, self: any = null, timeScale: number = 1) {
  33. let spinSkeleton = node.getComponent(sp.Skeleton);
  34. spinSkeleton.loop = isLoop;
  35. spinSkeleton.timeScale = timeScale;
  36. console.log("aaa----播放动画", animationName, isLoop);
  37. (completeCallback) ? spinSkeleton.setCompleteListener(completeCallback) : spinSkeleton.setCompleteListener(null);
  38. spinSkeleton.setAnimation(1, animationName, isLoop);
  39. // spinSkeleton.setEndListener(completeCallback);
  40. }
  41. public GetAnimationName(spinSkeleton: sp.Skeleton): string {
  42. return spinSkeleton.animation;
  43. }
  44. }