CCSAnimationUtils.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export default class CCSAnimationUtils
  2. {
  3. /**
  4. * 设置动画速度
  5. * @param target
  6. * @param animation
  7. * @param speed
  8. */
  9. public static SetAnimationSpeed(target:cc.Animation,animation:string,speed:number):void{
  10. let state:cc.AnimationState=target.getAnimationState(animation);
  11. if(state==null){
  12. throw new Error(target.node.name+"找不到动画:"+animation);
  13. }
  14. state.speed=speed;
  15. }
  16. /**
  17. * 设置动画事件帧
  18. * @param target
  19. * @param clipName
  20. * @param data
  21. */
  22. public static SetAnimationEvent(target:cc.Animation,clipName:string,events:any[]):void{
  23. let isTrue:boolean=false;
  24. let clips:cc.AnimationClip[]=target.getClips();
  25. clips.forEach(element => {
  26. if(element.name==clipName){
  27. events.forEach(eventData => {
  28. element.events.push(eventData);
  29. });
  30. isTrue=true;
  31. }
  32. });
  33. if(isTrue==false){
  34. throw new Error(target.name+"找不到:"+clipName+"动画,无法设置动画事件回调");
  35. }
  36. }
  37. }