| 123456789101112131415161718192021222324252627282930313233343536373839 | 
							- import { Animation, AnimationClip, Node, Sprite, SpriteFrame, Vec3 } from "cc";
 
- export class Tools {
 
-     
 
-     static createNode(parent?: Node, pos?: Vec3):Node{
 
-         const node = new Node();
 
-         parent && node.setParent(parent);
 
-         pos && node.setPosition(pos);
 
-         return node;
 
-     }
 
-     static createSprite(frame: SpriteFrame, parent?: Node, pos?: Vec3): Node{
 
-         const node = this.createNode(parent, pos);
 
-         node.addComponent(Sprite).spriteFrame = frame;
 
-         return node;
 
-     }
 
-     static createAnimation(frames: SpriteFrame[], sample: number, obj: Node | Animation, mode: AnimationClip.WrapMode = AnimationClip.WrapMode.Normal){
 
-         let ani: Animation;
 
-         if(obj instanceof Animation){
 
-             ani = obj;
 
-         }else{
 
-             ani = obj.addComponent(Animation);
 
-         }
 
-         //添加动画剪辑
 
-         const clip = AnimationClip.createWithSpriteFrames(frames, sample);
 
-         clip.wrapMode = mode;
 
-         ani.addClip(clip);
 
-         ani.defaultClip = clip;
 
-         return ani;
 
-     }
 
-     static randomNumber(num: number): number{
 
-         return Math.floor(Math.random() * num)
 
-     }
 
- }
 
 
  |