| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- const { ccclass, property } = cc._decorator;
- /**
- * 动画工具类
- * @author 薛鸿潇
- */
- @ccclass
- export default class TweenUtil {
- /**
- * 缓动类型
- */
- public easing: typeof TweenEasing = TweenEasing
-
- /**
- * 缩放效果
- * @param node 动画节点
- * @param time 动画时间
- * @param start_scale 起始缩放属性
- * @param end_scale 目标缩放属性
- * @param complete_fun 完成回调
- */
- public scale(node: cc.Node, time: number = 0.15, start_scale: number = 0, end_scale: number = 1, complete_fun?: Function, easing?: keyof typeof TweenEasing) {
- node.scale = start_scale;
- let scale1 = cc.tween().to(time, { scale: end_scale }, { easing: easing });
- let call1 = cc.tween().call(() => { if (typeof complete_fun == 'function') complete_fun(); })
- cc.tween(node).then(scale1).then(call1).start()
- }
- /**
- * 缩放效果
- * @param node 动画节点
- * @param time 动画时间
- * @param start_scale 起始缩放属性
- * @param end_scale 目标缩放属性
- * @param complete_fun 完成回调
- */
- public scaleX(node: cc.Node, time: number = 0.15, start_scale: number = 0, end_scale: number = 1, complete_fun?: Function, easing?: keyof typeof TweenEasing) {
- node.scaleX = start_scale;
- let scale1 = cc.tween().to(time, { scaleX: end_scale }, { easing: easing });
- let call1 = cc.tween().call(() => { if (typeof complete_fun == 'function') complete_fun(); })
- cc.tween(node).then(scale1).then(call1).start()
- }
- /**
- * 缩放移动效果
- * @param node 动画节点
- * @param time 动画时间
- * @param start_scale 起始缩放属性
- * @param end_scale 结束缩放属性
- * @param end_pos 结束节点位置
- * @param complete_fun 完成回调
- */
- public scaleParallelMove(node: cc.Node, time: number = 0.15, start_scale: number = 0, end_scale: number = 1, end_pos: cc.Vec2 = cc.Vec2.ZERO, complete_fun?: Function) {
- node.scale = start_scale;
- let scale1 = cc.tween().to(time, { scale: end_scale });
- let pos1 = cc.tween().to(time, { position: new cc.Vec3(end_pos.x, end_pos.y, 0) });
- let call1 = cc.tween().call(() => { if (typeof complete_fun == 'function') complete_fun(); })
- let parallel = cc.tween().parallel(scale1, pos1)
- cc.tween(node).then(parallel).then(call1).start();
- }
- /**
- * 移动效果
- * @param node
- * @param time
- * @param complete_fun
- */
- public move(node: cc.Node, time: number = 0.15, start_pos: cc.Vec2 = cc.Vec2.ZERO, end_pos: cc.Vec2 = cc.Vec2.ZERO, complete_fun?: Function, easing?: keyof typeof TweenEasing) {
- node.setPosition(start_pos);
- let pos1 = cc.tween().to(time, { position: new cc.Vec3(end_pos.x, end_pos.y, 0) }, { easing: easing });// cc.easeOut(3)
- let call1 = cc.tween().call(() => { if (typeof complete_fun == 'function') complete_fun(); })
- cc.tween(node).then(pos1).then(call1).start();
- }
- }
- /**
- * 缓动类型
- */
- enum TweenEasing {
- linear,
- smooth,
- fade,
- quadIn,
- quadOut,
- quadInOut,
- quadOutIn,
- cubicIn,
- cubicOut,
- cubicInOut,
- cubicOutIn,
- quartIn,
- quartOut,
- quartInOut,
- quartOutIn,
- quintIn,
- quintOut,
- quintInOut,
- quintOutIn,
- sineIn,
- sineOut,
- sineInOut,
- sineOutIn,
- expoIn,
- expoOut,
- expoInOut,
- expoOutIn,
- circIn,
- circOut,
- circInOut,
- circOutIn,
- elasticIn,
- elasticOut,
- elasticInOut,
- elasticOutIn,
- backIn,
- backOut,
- backInOut,
- backOutIn,
- bounceIn,
- bounceOut,
- bounceInOut,
- bounceOutIn
- }
|