export enum EasingEnum { quadIn = 0, quadOut = 1, quadInOut = 2, cubicIn = 3, cubicOut = 4, cubicInOut = 5, quartIn = 6, quartOut = 7, quartInOut = 8, quintIn = 9, quintOut = 10, quintInOut = 11, sineIn = 12, sineOut = 13, sineInOut = 14, expoIn = 15, expoOut = 16, expoInOut = 17, circIn = 18, circOut = 19, circInOut = 20, elasticIn = 21, elasticOut = 22, elasticInOut = 23, backIn = 24, backOut = 25, backInOut = 26, bounceIn = 27, bounceOut = 28, bounceInOut = 29, smooth = 30, fade = 31 } const { ccclass, property } = cc._decorator; @ccclass export default class TweenNormal extends cc.Component { @property duration: number = 2; @property startScale: number = 1; @property targetScale: number = 1; // @property(cc.Vec2) // Pos1: cc.Vec2 = new cc.Vec2(0, 50); // @property(cc.Vec2) // Pos2: cc.Vec2 = new cc.Vec2(0, 0); // currentPos: cc.Vec2 = new cc.Vec2(0, 0); @property intervalTime: number = 1; @property isLoop: boolean = true; @property({ type: cc.Enum(EasingEnum) }) public easings: EasingEnum = EasingEnum.smooth; callback: Function = null; onLoad() { this.Tweens(); } /** * 播放缩放动画 */ public Tweens() { let tweens = cc.tween(); //, position: this.currentPos tweens.to(this.duration, { scale: this.targetScale }, { easing: EasingEnum[this.easings] }); tweens.call(() => { this.node.setScale(this.startScale); // console.log('缓动结束回调'); if (this.callback) this.callback(); }); (this.isLoop) ? cc.tween(this.node).repeatForever(tweens).start() : cc.tween(this.node).repeat(1, tweens).start(); } }