1234567891011121314151617181920212223242526272829303132333435 |
- 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;
- }
- }
|