question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Tween.get multiple targets

See original GitHub issue

It’s nice to have multiple targets in Tween.get to reduce the number of lines in code:

var target_a = new createjs.Shape();
var target_b = new createjs.Shape();
var targets = [target_a, target_b];

createjs.Tween.get(targets, {loop:true}, true)
    .to({x: 300, y: 300}, 3000);

// also support the following:
createjs.Tween.get(target_a, {loop:true}, true)
    .to({x: 300, y: 300}, 3000);
createjs.Tween.get(target_b, {loop:true}, true)
    .to({x: 300, y: 300}, 3000);

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gskinnercommented, Mar 2, 2017

And of course, you could use Timeline, which is specifically designed for coordinating parallel tweens.

1reaction
lannymcniecommented, Mar 2, 2017

@zur4ik If the tweens have the same duration, you can just create two separate ones, but only add a call() to one of them (the longer). Tweens are deterministic, so they should play at the duration specified, no matter what the CPU performance is.

If you have complex tween chains, and don’t want to determine the length, you could just have them both call the same method, and ensure both have finished before moving on:

tween1 = createjs.Tween.get(obj).to({}, 1000).wait(1000).to({}, 3000).wait(1000).etc()
  .call(tweenComplete);
tween2 = createjs.Tween.get(obj2).etc()
  .call(tweenComplete);

var tweensComplete = 0;
function tweenComplete(event) {
  tweensComplete++;
  if (tweensComplete == 2) {
    // do something
  }
}

Obviously that is just an example, but those are probably your best options. There is no framework in TweenJS to manage multiple objects with a single tween, so you will have to come up with something that works for your case.

Cheers,

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best way to apply a modifier tween on multiple targets? - GSAP
Greetings! I'm using Blakes clever method of using a mouse object to update a modifier function ( See the Pen ...
Read more >
TweenJS multiple tweens on multiple targets - Stack Overflow
The idea is to tween myimage inside the container to a new x and y position. This should be followed by rotating the...
Read more >
Multitarget tween with different parameters - Phaser 3
Hello, let's say I have a tween for a large array of targets. Is there a way to set slightly different parameters for...
Read more >
Adding tween targets to existing tween - Phaser 3
However, this seems inefficient as I know that you can have one tween with multiple targets, so having loads of tweens that all...
Read more >
TweenJS v1.0.0 API Documentation : Tween - CreateJS
Multiple tweens can share a target, however if they affect the same properties there could be unexpected behaviour. To stop all tweens on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found