Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added preservation flag in TWEEN.update to be able to go backward in time #271

Merged
merged 1 commit into from
Aug 1, 2016
Merged

added preservation flag in TWEEN.update to be able to go backward in time #271

merged 1 commit into from
Aug 1, 2016

Conversation

sairoutine
Copy link
Contributor

I saw #93 pull request.
However, the pull request is not merged yet and the owner had gone away.

I need to be able to preserve tweens when It's done.

Thanks.

@dalisoft
Copy link
Collaborator

Hi @sairoutine.
I no where seen time goes reverse.
But you can do reverse feature for that tween you want.
Sorry for bad english, so i think you understand me.

@sairoutine
Copy link
Contributor Author

Hi @dalisoft.
Thank you for your advice.

I don't know reverse feature. What is it?

@dalisoft
Copy link
Collaborator

Hi @sairoutine
reverse feature is tween like this

var tween = new TWEEN.Tween({x:0}).to({x:300}, 200).reverse().start();
     tween.onUpdate(function(_object){
     console.log(_object);
// {x:300}
// {x:299}
// {x:298}
// ...
// {x:1}
// {x:0}
     });

@sairoutine
Copy link
Contributor Author

sairoutine commented Jul 31, 2016

hmm.. the code you gave me does not perform correctly.
I can't find reverse method in tween's source code.
Are there any more approach?

@mikebolt mikebolt merged commit f0b25ac into tweenjs:master Aug 1, 2016
@mikebolt
Copy link
Contributor

mikebolt commented Aug 1, 2016

Looks good, thanks. I just merged this request. I also wrote an extra unit test to make sure that if you update past a finished tween with preserve set to true, you can still call TWEEN.update with a time during the tween and get the expected tweened values. I will commit and merge that extra unit test sometime later.

Could you please update the user guide and documentation to explain how to use this feature, and perhaps add an example? If not, let me know, so I can do it instead.

@dalisoft I think having a chainable reverse feature would be cool. We should add that to the next version. However, this new preserve flag feature is still necessary for what sairoutine is trying to do, I think.

@sairoutine
Copy link
Contributor Author

Thank you for merging!
I was mistaken about dalisoft's proposal, sorry.

Could you please update the user guide and documentation to explain how to use this feature, and perhaps add an example?

All right! I'm going to make a pull request which update documentation.

Thanks.

@dalisoft
Copy link
Collaborator

dalisoft commented Aug 2, 2016

@sairoutine @mikebolt Do you know about GSAP (Greensock Animation Platform) reverse feature? Same feature, i tried add to few year ago, but no merged. Then i maked own JS Animation Engine. Now "Deprecated due of no user". But you can see history and see demo. Thanks

trusktr added a commit that referenced this pull request Jul 26, 2024
…group

feat: the `tween.group(group)` method now has a reciprocal `tween.remove()`
method that will remove a tween from its associated group, and unassociate the
group. `tween.group()` without an arg is no longer valid, see breaking changes
and migration below.

fix: when a tween is stopped before its end time, do not allow its update method
to continue, therefore preventing logic (f.e. repeat logic) from being
triggered

docs: improved the docs, adding some missing information, removing all examples
of the global `TWEEN` group which has been deprecated, and adding docs on how to
manage groups of tweens. Also updated samples to use `import` syntax for
importing Tween, avoiding the use of the `TWEEN` UMD global variable which has
been deprecated.

feat: A new `Group.allStopped()` method returns true if all tweens in
a group are not playing (i.e. stopped, and not paused), otherwise false.
Useful for stopping an animation loop once all tweens in a group have
finished their animation.

BREAKING:

- Tweens are no longer automatically added or removed from groups by default
  when you call any Tween methods such as `start()`, `stop()`, or `pause()`, and
  the `preserve` parameter to `Group.update()` now defaults to `true` and is
  deprecated to be removed in a future major version.
  - MIGRATION: To keep old behavior for a while, explicitly call
    `group.update()` with `false` for the second parameter. To migrate forward, do
    not rely on automatic add/remove of tweens, and instead add/remove tweens
    to/from groups manually.
- `Group.update()` no longer returns a boolean indicating if all tweens
  have been removed.
  - MIGRATION: Don't rely on auto-add/remove to/from groups. This
    boolean return was previously useful for stopping an animation loop
    once all tweens were finished animating. Instead, use the new
    `Group.allStopped()` method to check if all tweens in a group are stopped in
    order to determine whether or not to continue an animation loop.
- The second `group` parameter to `Tween.constructor` now defaults to
  `undefined` instead of the global `TWEEN` group. Additionally it
  accepts a value of `true` to restore the old default behavior. The
  `true` value is deprecated and will be removed in a future major
  version.
  - MIGRATION: For the time being the parameter can be set to `true` to restore
    the old behavior. To migrate forward, use `tween.group(group)` or
    `group.add(tween)` instead.
- The argless `tween.group()` signature has been removed.
  - MIGRATION: Use `group.add(tween)` or `group.remove(tween)` instead.
    `tween.group(TWEEN)`, `TWEEN.add(tween)`, and `TWEEN.remove(tween)` will also
    work for now, but they are deprecated and will be removed in a future major
    version.
- `Group.update`'s second parameter `preserve` defaults to `true` now, and is
  deprecated to be removed in a future major version, at which point tweens of a
  group will no longer be automatically added/remove to/from a group when calling
  any Tween methods such as `start()`, `pause()`, or `stop()`.
  - MIGRATION: For now, explicitly set the parameter to `false` to restore old
    default behavior when calling `group.update()`. To migrate forward, do not
    rely on the automatic add/remove behavior, and instead manually add or remove
    tweens to or from groups.
- To make the fix for `tween.update()` to be a no-op for stopped tweens, we had
  to break an undocumented feature that allowed tweens to move backward in time
  (#271).
  - MIGRATION: To move tweens backward in time after they have already
    completed, first call `tween.start(startTime)` then proceed to call
    `tween.update(time)` in reverse order as before (see the unit test with "go
    backward in time" in its name). Without calling `tween.start()` nothing will
    happen because stopped/completed tweens will now always return early from
    `update()`, as they are considered to be no longer running.
@trusktr
Copy link
Member

trusktr commented Jul 26, 2024

v24.0.0 changed the default value of Group.update()s preserve parameter to true, and is deprecated to be removed in a future major version.

To go in reverse, one must now call tween.start(startTime) before applying reverse values. The unit test is updated to show how:

tween.js/src/tests.ts

Lines 152 to 155 in c92f761

// If you want to go backward in time, start back at the beginning
// first, then go to any time between the start and end time.
t1.start(0)
t2.start(0)

More details in the release notes:

https://github.com/tweenjs/tween.js/releases/tag/v24.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants