Skip to content

Simplify Tween, remove some stuff, make it easier to maintain. #655

Open
@trusktr

Description

@trusktr

Proposed (welcome to debate):

  • Ensure maximal ES Module support
  • remove legacy CommonJS after Electron ESM comes out
  • Remove the autostart parameter from tween.update(time, autostart). It makes the API less intuitive: for example if you call stop() and then the next animation frame calls update() and restarts the tween, it seems like stop() is not working. Better to make the APIs explicit: tweens will start and stop only when you tell them to, regardless if update is being called, and update does only one thing well (update the time).
    • This also allows us to eliminate confusion with onStart. Currently you call tween.start(), but onStart will be be fired until update() is called (f.e. in the next animation frame). Instead, we can make it be called immediately so that any state that should be initially set for the tween is guaranteed to be set, regardless of update().
  • Remove the TWEEN singleton, make Tweens start with no Group by default
    • docs: Teach people how to make a Tween and update it directly.
    • docs: Teach them that if they want to update multiple Tweens at once, they must make a Group.
    • This eliminates possible errors people will have when they clash tweens from two or more separate pieces of code (when using the current TWEEN)
    • explicitly managing each tween, or explicitly making Groups, will naturally lead to people writing componentized code with lowered chance of issues.
    • this leads to understanding of what is going on, rather than proper code being non-obvious up front
  • Remove relative values. It involves detecting strings for little convenience. People can just use math on their side with not much more effort.
  • Remove the dynamic-to feature. It isn't used often, and much internal complication.
  • Remove array of to-values.
    • Also adds quite some complexity.
    • It seems that when we do this, we inadvertently destroy the meaning of an easing curve because the actual number output is no longer on that curve so the meaning is obscure, unless we do very special math to determine proper values to use such that a new curve makes sense.
    • The same math skill required for the previous point may instead be used to chain multiple tweens together, which gives more capabilities such as specific curves between each value. To emulate the array of values, chain tweens together with linear curves, then interpolate all of them with a single higher-level tween using a single curve.
    • The previous point allows much more options than the inflexible feature of to-values. To-values is a shortcut for the previous point with a linear chain and directing tween.
    • Downside: lose ability to choose interpolation method, f.e. bezier, which is useful for making a smooth curve out of the discrete to-values (f.e. "animate along a smooth path calculated from the discrete sharp values").
      • provide an alternative that doesn't complicate tween directly? F.e. Three.js has Path and Curve tools, instead animate position along such primitives specialized for that purpose. Perhaps we show a demo of that here, after removing to-values.
  • Remove or replace .yoyo. Provide a reverse function that can return a new tween instance with reversed data.
    • simplifies tween logic.
    • then: tween.chain(tween.reverse().chain(tween))
    • Perhaps instead of removing, tween.yoyo() can be a shortcut for the previous point. The main idea is that the yoyo state is not intertwined inside the regular tween state like it currently is. Instead, two separate tweens each have their own state.
  • Replace tween.chain with a Sequence (or more advanced Timeline) feature.
    • This composes tween independently of each other, so they don't need to have state remembering who they are chained to. This allows way more flexible new options (Timeline) like playing tweens in parallel, not just in sequence, etc.
  • improved testing.
    • run unit tests in browsers, because that's where Tween is used more often.
    • Add a way to perform visual snapshot testing so that we may catch issues that unit tests may not, by snapshotting results of visual animations

What else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions