Jump to content
Search Community

Using an Array to set bezier points [SOLVED]

dbooth test
Moderator Tag

Recommended Posts

There must be a better way to do this.

 

I am sort of making leaves fall. I want them to swing from side to side (from bezier point to bezier point) as they land on the ground.

 

The bezier requires an array of values.

 

I dynamically generate an array of values for each leaf.

 

If I used a separate tween for each swing then I lose the continuity of one very long, smooth tween and the easing that comes with it.

 

I'm using version 10.

 

There must be a better way to dynamically create the following:

 

private function makeSwings(signTile:DisplayObject3D)
		{
			var bezPoints:uint = 14; //would like this to be a dynamic number

			var swingArray:Array = [];

			// pinacle
			swingArray[0] = [];
			swingArray[0][0] = ( -1200 * Math.random()) + 600;
			swingArray[0][1] = signTile.y + Math.random() * SH;
			swingArray[0][2] = ( -1000 * Math.random()) + 1000;

			// first swing
			swingArray[1] = [];
			swingArray[1][0] =  swingArray[0][0] + ( -1200 * Math.random()) + 600;
			swingArray[1][1] = swingArray[0][1]  - 75;
			swingArray[1][2] = swingArray[0][2] - 100;

			// subsequent swings up to bezPoints
			for (var i:uint = 2; i < bezPoints+1;i++)
			{

				//  NB - the following calculations will change.  
				//  The concept of their implementation will not change.

				swingArray[i] = []; //this defines the "row"		
				//swingArray[i][0] = ( -1200 * Math.random()) + 600;
				swingArray[i][0] = 
				//swingArray[i][1] = signTile.y + Math.random() * SH; 
				swingArray[i][1] = swingArray[i - 1][1] - 75;
				//swingArray[i][2] = ( -1000 * Math.random()) + 1000;
				swingArray[i][2] = swingArray[i - 1][2] - 125;
			}

			TweenMax.to(signTile, 8, { timeScale: 0.6, 
			x:swingArray[bezPoints][0], y:swingArray[bezPoints][1],z:swingArray[bezPoints][2], 
				bezier:[ 
				{x:swingArray[1][0], y:swingArray[1][1], z:swingArray[1][2] },
				{x:swingArray[2][0], y:swingArray[2][1], z:swingArray[2][2] },
				{x:swingArray[3][0], y:swingArray[3][1], z:swingArray[3][2] },
				{x:swingArray[4][0], y:swingArray[4][1], z:swingArray[4][2] },
				{x:swingArray[5][0], y:swingArray[5][1], z:swingArray[5][2] },
				{x:swingArray[6][0], y:swingArray[6][1], z:swingArray[6][2] },
				{x:swingArray[7][0], y:swingArray[7][1], z:swingArray[7][2] },
				{x:swingArray[8][0], y:swingArray[8][1], z:swingArray[8][2] },
				{x:swingArray[9][0], y:swingArray[9][1], z:swingArray[9][2] },
				{x:swingArray[10][0], y:swingArray[10][1], z:swingArray[10][2] },
				{x:swingArray[11][0], y:swingArray[11][1], z:swingArray[11][2] },
				{x:swingArray[12][0], y:swingArray[12][1], z:swingArray[12][2] },
				{x:swingArray[13][0], y:swingArray[13][1], z:swingArray[13][2] },
				], ease:Sine.easeInOut } );
		}

 

Thanks to all.

 

(by the way, I'm a member of the "club" and transform from a point/center saved my bacon this year.

It was well worth the money.)

 

thanks,

 

 

d. Booth

Toronto

Link to comment
Share on other sites

It was a little tough to decipher a few things that may or may not have been commented out, but I think this is close to a much more simplified version:

 

private function makeSwings(signTile:DisplayObject3D)
{
var bezPoints:uint = 14; //would like this to be a dynamic number

var beziers:Array = [];

// pinacle
beziers[0] = {x:( -1200 * Math.random()) + 600, 
			  y:signTile.y + Math.random() * SH, 
			  z:( -1000 * Math.random()) + 1000};

// first swing
beziers[1] = {x:beziers[0].x + ( -1200 * Math.random()) + 600,
			  y:beziers[0].y - 75,
			  z:beziers[0].z - 100};

var xy:Number;
// subsequent swings up to bezPoints
for (var i:uint = 2; i 	{
   //  NB - the following calculations will change. 
   //  The concept of their implementation will not change.
	xy = beziers[i - 1].y - 75;
	beziers[i] =  {x:xy, y:xy, z:beziers[i - 1].z - 125};
}

TweenMax.to(signTile, 8, { timeScale:0.6, bezier:beziers, ease:Sine.easeInOut } );
}

 

Basically, there's no point to storing all your values in a separate array and then trying to manually pick out all the values and plug them into bezier objects in the tween. Just build it that way from the start.

 

Hope that helps!

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...