Having trouble assigning tweens to objects dynamically
Hi all!
I am currently working on a lens which has the functionality of an object which tweens from one side of the screen to the other on tap, then returns on the second tap etc. I am setting start positions and end positions by running a global counter which flips between 0 and 1 to set this by using %2 (I also get 0 to 3 on the same counter using %4 for some other functionality).
I would like to dynamically add a tween to a scene object from the touch handler using something along the lines of:
var startPos = something;
var endPos = something else;
global.scene.rootObject(the object to move).addTween(new TWEEN.Tween(startPos).to(endPos..... etc.);
But I can't seem to work out how to dynamically target the object to add the tween. I have tween manager added in the objects, and the object I want to move has the tween.js script attached as a component. Is there a way to achieve this or some workaround?
thanks!
Further to this, I have tried something else:
I set up two tweens called tweenLR and tweenRL in a script attached to the object I want to move. That script is set to initialise on 'lens turned on', as is the tween.js script. I then try to trigger the tweens from the touch handler using:
global.tweenManager.startTween(global.scene.getRootObject(5), "tweenLR");
and
global.tweenManager.startTween(global.scene.getRootObject(5), "tweenRL");
but it throws an error "Tween Manager: Tween, tweenLR, is not found. Ensure that tweenLR is on "Lens Turn On" and that Tween Manager is at the top of the Objects Panel". Tween Manager is correctly placed so still stuck.
cheers
Fixed! I rolled back from custom coding the tweens, and just stacked some tweenTransform scripts on each layer of the parallax layers. Calling these from the main touch event handler seems to work fine so all good!
Hi Caleb,
Thank you for sharing! Glad you were able to figure it out.
Cheers,
Karolina