Code Monkey home page Code Monkey logo

Comments (5)

trusktr avatar trusktr commented on June 2, 2024 1

This seems unintuitive indeed, so will mark as a bug. Do you have a sample? Here's a starting point: https://codepen.io/trusktr/pen/OJRQjZw

from tween.js.

NyaNguyen avatar NyaNguyen commented on June 2, 2024

Not sure if this small code was required, but here is the demonstration that the tween from a Group's array gets removed after pausing a tween:

const DATA = { 'X': 0 };
const TWEEN_DATA = { 'X': 1000 };
const TWEEN_GROUP = new TWEEN.Group();

new TWEEN.Tween(DATA, TWEEN_GROUP).to(TWEEN_DATA).duration(1000).onUpdate(UpdateCallback).start();

function UpdateCallback() {
    console.log(DATA);
}

function Animate() {
    requestAnimationFrame(Animate);
    TWEEN_GROUP.update();
}

Animate();

setTimeout(function () {
    console.log('Array Length Before Pausing: ' + TWEEN_GROUP.getAll().length);
    TWEEN_GROUP.getAll()[0].pause();
    console.log('Array Length After Pausing: ' + TWEEN_GROUP.getAll().length);
}, 500);

from tween.js.

trusktr avatar trusktr commented on June 2, 2024

Yeah, totally I see that. I meant, do you have an example of a problem this is causing?

Even long ago before TWEEN was made into a Group, and before there was pause(), Tweens were added or removed on start/stop:

var TWEEN = TWEEN || (function () {

So we need to see an example of the problem.

from tween.js.

MasatoMakino avatar MasatoMakino commented on June 2, 2024

I found a code related to this issue.

tween.js/src/Tween.ts

Lines 284 to 285 in e01bbdb

// eslint-disable-next-line
this._group && this._group.remove(this as any)

tween.js/src/Tween.ts

Lines 301 to 302 in e01bbdb

// eslint-disable-next-line
this._group && this._group.add(this as any)

All tween instances hold a reference to a group. On pause, tween removes itself from a group and re-adds itself on resume.

tween.js/src/Tween.ts

Lines 393 to 394 in e01bbdb

update(time = now(), autoStart = true): boolean {
if (this._isPaused) return true

Tween.update() skips paused tween. Because of this, it is not necessary to remove and re-add tweens to a group.


The downside of this behavior is that it can be confusing when users use Group to manage and manipulate their tween.

The advantage of this behavior is that the update loop is faster if the mainGroup holds a large number of paused tween.

from tween.js.

trusktr avatar trusktr commented on June 2, 2024

Ah indeed, should be easy to implement!

from tween.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.