You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.8 KiB
44 lines
1.8 KiB
import { animation, AnimationClip, IVec2, SpriteFrame } from "cc";
|
|
|
|
/**帧动画片段创建工具 */
|
|
export default class FrameClip{
|
|
private static key: string = '';
|
|
/**动画数据 */
|
|
private static _animationClipInfoMap: Map<string, AnimationClip> = new Map();
|
|
static getAnimationClip(UrlName: string, actionName: string, res: SpriteFrame[], scale: IVec2[], speed: number = 1) {
|
|
this.key = `${UrlName}_${actionName}`;
|
|
let tAnimationClip: AnimationClip = this._animationClipInfoMap.get(this.key);
|
|
if (!tAnimationClip) {
|
|
tAnimationClip = AnimationClip.createWithSpriteFrames(res, 60);
|
|
|
|
/**图集锚点动画添加 */
|
|
if (scale && scale.length) {
|
|
let curve = tAnimationClip.getTrack(0).channels()[0].curve.times() as number[];
|
|
let Track = new animation.VectorTrack();
|
|
Track.path.toComponent("cc.UITransform");
|
|
Track.path.toProperty("anchorPoint");
|
|
Track.componentsCount = curve.length;
|
|
/** 0 : X */
|
|
for (let m = 0; m < curve.length; m++) {
|
|
Track.channels()[0].curve.addKeyFrame(curve[m], scale[m].x)
|
|
}
|
|
/** 1 : Y */
|
|
for (let m = 0; m < curve.length; m++) {
|
|
Track.channels()[1].curve.addKeyFrame(curve[m], scale[m].y)
|
|
}
|
|
tAnimationClip.addTrack(Track)
|
|
}
|
|
|
|
tAnimationClip.speed = speed;
|
|
tAnimationClip.name = actionName;
|
|
this._animationClipInfoMap.set(this.key, tAnimationClip);
|
|
}
|
|
return tAnimationClip;
|
|
}
|
|
|
|
static ClearAllClip() {
|
|
delete this._animationClipInfoMap;
|
|
this._animationClipInfoMap = new Map();
|
|
}
|
|
|
|
}
|