How to get X and Y for TweenPosition from A to B node?

Hi, I have two group nodes (Node A and Node B)
Node A have children which should move to Node B with TweenAnimation one by one.
 
Currently, the only way I do is switchParent(NodeB) and then playForward.
But, node's z-index is displayed in reverse order. Is there any way to move tween from A to B, but changing parent only after tween finishes animating?
 
Something like this:
var cards = [...];
cards.forEach(function(cardNode, i) { // cardNode have parent NodeA
var tween = cardNode.addScript('qc.TweenPosition');

tween.addListenerOnce(tween.onFinished, function (tween) {
var currentCard = tween.gameObject;
currentCard.switchParent(NodeB);
});

tween.from.x = cardNode.anchoredX; // wrong position if I don't use switchParent before
tween.from.y = cardNode.anchoredY; // same here.
tween.to.x = (NodeB.width / 2); // same here I guess, I need it to be placed at NodeB's center.
tween.to.y = 0;
tween.duration = 0.15;
tween.delay = i * 0.3; // one by one

tween.playForward();
});
Has invited:

lijh

Favor from: warlockn

I wrote a demo for this and you can refer to it.
var test = qc.defineBehaviour('qc.engine.test', qc.Behaviour, function() {
}, {
nodeA: qc.Serializer.NODE,
nodeB: qc.Serializer.NODE
});

test.prototype.onEnable = function() {
var self = this;

var i = 0;
self.nodeA.children.forEach(function(child) {
var tween = child.addScript('qc.TweenPosition');

self.addListener(tween.onFinished, function (tween) {
var currentCard = tween.gameObject;
currentCard.switchParent(self.nodeB);
}, self);

tween.from = new qc.Point(child.x, child.y);
tween.to = self.nodeA.toLocal(self.nodeB.getWorldPosition());
tween.duration = 1.5;
tween.delay = (i++) * 0.3; // one by one

tween.playForward();
});
};

warlockn

Favor from:

Thanks! solved it.

To reply to a question, please Login or registered