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

Alternative to forcing an update to two instance #92

Open
dickinson0718 opened this issue Aug 7, 2024 · 0 comments
Open

Alternative to forcing an update to two instance #92

dickinson0718 opened this issue Aug 7, 2024 · 0 comments
Labels
question Further information is requested

Comments

@dickinson0718
Copy link
Collaborator

This is really an observation and not a issue -- something to think about. I know that I don't time this summer and I don't think you do either.

This might be better than EventBus.fire("update-two-instance",{}) when updating plottable objects that depend on other twoJs objects that must be updated before their dependent objects. We were having trouble updating the polygon fill because we needed the segments to be updated correctly by the two instance. There is a way to bind an event listener to an two js event.

Here is the (totally unhelpful) documentation.

Here is an example.

In the example, notice how the 'update' event is bound to the function in

two.bind('update', function(frameCount, timeDelta) {

  if (typeof timeDelta !== 'number') {
    return;
  }

  tot += timeDelta/300
  for (let i = 0; i < two.scene.children.length; i++) {
    const child = two.scene.children[i];
    child.rotation +=  timeDelta / 3000;
    child.height =  200 + 100*Math.sin(tot); 
    child.width =  200 - 100*Math.sin(tot); 
  }

});

We could bind a polygon.update() function to the update event and we can unbind it as well. We would have to manage what was bound to 'update` so that we don't slow down the execution.

I wrote this note so that next summer, I'll remember to think about this.

@dickinson0718 dickinson0718 added the question Further information is requested label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant