diff --git a/cocos/tween/export-api.ts b/cocos/tween/export-api.ts index 680813b295..351d9aba81 100644 --- a/cocos/tween/export-api.ts +++ b/cocos/tween/export-api.ts @@ -18,4 +18,7 @@ export type TweenEasing = export interface ITweenOption { easing?: TweenEasing | ((k: number) => number); progress?: (start: number, end: number, current: number, ratio: number) => number; + onStart?: Function; + onUpdate?: Function; + onComplete?: Function; } \ No newline at end of file diff --git a/cocos/tween/tween-action.ts b/cocos/tween/tween-action.ts index 622dcf1671..1560ba8ce9 100644 --- a/cocos/tween/tween-action.ts +++ b/cocos/tween/tween-action.ts @@ -63,18 +63,9 @@ function TweenOptionChecker (opts: ITweenOption) { if (opts['interpolation']) { warn(header + 'interpolation' + message); } - if (opts['onStart']) { - warn(header + 'onStart' + message); - } if (opts['onStop']) { warn(header + 'onStop' + message); } - if (opts['onUpdate']) { - warn(header + 'onUpdate' + message); - } - if (opts['onComplete']) { - warn(header + 'onComplete' + message); - } } export class TweenAction extends ActionInterval { @@ -170,6 +161,7 @@ export class TweenAction extends ActionInterval { } } } + if (this._opts.onStart) { this._opts.onStart(); } } update (t: number) { @@ -182,7 +174,7 @@ export class TweenAction extends ActionInterval { let easingTime = t; if (opts.easing) easingTime = opts.easing(t); - let progress = this._opts.progress; + let progress = opts.progress; for (const name in props) { let prop = props[name]; let time = prop.easing ? prop.easing(t) : easingTime; @@ -208,6 +200,8 @@ export class TweenAction extends ActionInterval { target[name] = prop.current; } + if (opts.onUpdate) { opts.onUpdate(); } + if (t == 1 && opts.onComplete) { opts.onComplete(); } } progress (start: any, end: any, current: any, t: number) {