optimize tween (#6205)

* optimize tween

* tweaks
This commit is contained in:
jiaxin.lai
2020-02-21 19:10:48 +08:00
committed by GitHub
parent 5e4b21c5ca
commit a54cd7fb94
2 changed files with 7 additions and 10 deletions
+3
View File
@@ -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;
}
+4 -10
View File
@@ -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) {