Browse Source

added stop/cancel methods

develop
Rob Colbert 2 years ago
parent
commit
e27f91f52e
  1. 23
      lib/nice-tween.js

23
lib/nice-tween.js

@ -100,6 +100,29 @@ export default class NiceTween {
return this;
}
/**
* Stops the currently running tween and advances to the end of the tween so
* the target game object will be in whatever state is expected at the end of
* this tween.
*/
stop ( ) {
this._progress = 1.0;
const term = this._easing(this._progress);
const current = { };
for (const property of this._properties) {
current[property] = NiceTween.lerp(this._from[property], this._to[property], term);
}
this.applyTargetUpdate(current);
this._state = 'finished';
}
/**
* Alias for stop
*/
cancel ( ) { this.stop(); }
applyTargetUpdate (current) {
if (typeof this._target === 'function') {
this._target(current);

Loading…
Cancel
Save