Jump to content
Search Community

Tween to Array Coordinates

goonzy test
Moderator Tag

Recommended Posts

Hi all,

 

I'm playing around with Away 3D (doing an well known oldskool fx.. Vectorbobs)... and basically, I'm trying to tween between 2 Objects and can't really find out what to do:

 

My code for the moment just does a yoyo repeat from 0 to obj coordinates. What I would like to do is go from 0 origin -> Obj A -> 0 origin -> Obj B.

 

heres my current code

function initObjects():void{
var vballs:Array=new Array(); // Array containing all sprites



// Arrays of X,Y,Z coordinates of sprites in 1st object
       var Bx:Array=[0,0,0,20,20,-20,-20,40,40,40,-40,-40,-40,80,80,80,80,-80,-80,-80,100,-100,-100,120,-120,-120,-120,140,140,140,-140,-140,180,180,-160,-160,-160,200,200,200,-200,-200,-200,-200,220,220,220,-220,-220,-220,240,240,-240,-240,-240,-260,-260,0,0,0,0,0,0,0,0,0];
var By:Array=[0,40,-40,40,-40,40,-40,20,0,-20,20,0,-20,20,0,-20,-40,20,0,-20,20,40,-40,20,40,0,-40,0,-20,-40,40,-40,0,-40,20,0,-20,20,0,-40,0,-20,-40,-60,20,-20,-40,20,-40,-80,20,-20,20,-40,-80,0,-20,0,0,0,0,0,0,0,0,0];
var Bz:Array= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

// Arrays of X,Y,Z Coordinates for Object B	
var	Bxx=[20,-20,-20,-20,40,-40,-40,60,-60,-60,80,-80,-80,100,100,100,100,100,-100,-100,-100,-100,-100,120,120,120,120,120,-120,-120,-120,-120,-120,20,-20,-20,-20,40,-40,-40,60,-60,-60,80,-80,-80,100,100,100,100,100,-100,-100,-100,-100,-100,120,120,120,120,120,-120,-120,-120,-120,-120];
var Byy=[-20,20,0,-20,-40,40,-40,-40,40,-40,-40,40,-40,40,20,0,-20,-40,40,20,0,-20,-40,40,20,0,-20,-40,40,20,0,-20,-40,-20,20,0,-20,-40,40,-40,-40,40,-40,-40,40,-40,40,20,0,-20,-40,40,20,0,-20,-40,40,20,0,-20,-40,40,20,0,-20,-40];
var Bzz=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20];
trace (Bz.length); // Just to check there's the same amount of data in all Arrays

// Creation of all the sprites needed.
var i:int=0;
while  (i		var ball:Sprite3D=new Sprite3D();
	ball.material=spr_mat;
	ball.distanceScaling = false;

	view.scene.addSprite(ball);

	vballs.push(ball);
	vballs[i].x=Bxx[i]+25;
	vballs[i].y=Byy[i]-35;
	vballs[i].z=Bzz[i]+55;



	i++;

	}

//1st tweening test.. Repeat yoyo with 1st object		
TweenMax.allFrom (vballs, 4, {x:0, y:0, z:0,repeat:-1, yoyo:true} );

//


}

 

Can someone help me on this as I'm not too "code litterate (and just understood the way arrays work :))

 

Thanxx in advance

Link to comment
Share on other sites

Hi toonzy,

 

you can just loop through your coordinates arrays and append tweens to a TimelineLite/Max.

 

this basic example provides a clear visual illustration of tweening an object from origin -> point a -> origin -> point b -> origin etc.

 

http://www.snorkl.tv/dev/objectGoMultip ... index.html

 

the code looks like this

import com.greensock.*;

var tl:TimelineMax = new TimelineMax({repeat:-1});

var objectsArray = new Array(red_mc, green_mc, blue_mc, orange_mc, pink_mc);

var objectsCount:Number = objectsArray.length;

//for every object or coordinate in an array do something:
for (var i:int = 0; i //tween to the next object / point
tl.append(TweenMax.to(ball_mc, .8, {x:objectsArray[i].x, y:objectsArray[i].y}));
//tween back to the origin
tl.append(TweenMax.to(ball_mc, .8, {x:origin_mc.x, y:origin_mc.y}));
}

 

 

cs4 source fla attached

Link to comment
Share on other sites

I'm not sure to understand... (but I might be thick :))

 

BAsically, I've got 66 objects to move to 66 positions (in my example) and with your example, if I change the destination MC to my Sprites array, it does not work the way I expect

 

in my loop

 

for (var j:int=0, i<66, i++{
              tl.append(TweenMax.to(vballs[j], .2, {x:Bxxx[j], x:Byyy[j], x:Byyy[j]})); // Array where all coords are set to x:0, y:0, z:0
	tl.append(TweenMax.to(vballs[j],.1, {x:Bx[j], y:By[j], z:Bz[j]})); // Array with obj 1 coords
	tl.append(TweenMax.to(vballs[j], .2, {x:Bxxx[j], y:Byyy[j], z:Bzzz[j]}));  //0
	tl.append(TweenMax.to(vballs[j],.1, {x:Bxx[j], y:Byy[j], z:Bzz[j]})); // Obj 2

 

All my objects go to the new coordinates, but one by one, while I'd like them to go all together. and the timeline does not take the new frames in account???

 

(I've put the values I use "hard" values)

Link to comment
Share on other sites

wait, all 66 objects are moving? what happened to the business about moving an object from origin to point A back to origin to point B?

 

i can see that I may have misunderstood your original question a bit but your latest post makes things even more confusing to me.

 

in your loop try using insert instead of append. that will make all the tweens happen at once and not one after the other

 

tl.insert(TweenMax.to(vballs[j],.1, {x:Bx[j], y:By[j], z:Bz[j]})); // Array with obj 1 coords

 

if you are just starting to get a hang of AS3, this goal may be a tad ambitious.

I'd suggest reading through the TimeliteMax documentation, and perhaps experimenting with some of the basics before tackling an integration with Away3D. even the little stuff is a lot of fun.

 

good luck on your project.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...