Striker
Striker

Reputation: 1

how to align movieClips in circular orbit?

circular alignment for movieclips in as3? i have problem in moving and align movieclips in circular manner

for(var i:int;i<15;i++)
{
    var obj:mc = new mc();
    obj.scaleX = obj.scaleY = 0.5;
    this.addChild(obj);

    obj.gotoAndStop(i);

    obj.centerX = 372.3;
    obj.centerY = stage.stageHeight/2;

    //for tilt objects 
    //obj.angle = 200 - i*36;

    obj.angle = i*24; //for spaceing objects 36 for 10;
    obj.radius = 300;
    itemArray.push(obj);
}
allign();

Upvotes: 0

Views: 273

Answers (1)

B Banda
B Banda

Reputation: 46

Use Trigonometric equations to position your MovieClips relative to a center.

Solution

          //Suppose the point center c={x:0, y:0}, and radius constant r=100;

          // define  pool of data type Vector for your Items(MovieClips)
          var objectPool:Vector.<Item>=new Vector.<Item>();

          //generate pool for your items and add them around the center

            var numItems:int=4;

            var angle:Number=360/numItems;

           //suppose you have a custom class ClipItem as a blue print for your clips
            var clipItem:ClipItem;

            var _x:Number, _y:Number;

             for(var i:int=0; i<numItems)
             {
                clipItem=new ClipItem;

                _x=c.x+Math.sin(angle)*r;
                _y=c.y+Math.cos(angle)*r;

                clipItem.x=_x; clipItem.y=_y;

                angle+=angle;
               //You might need reference to the clips for other interactions
               // such as moving them around. putting them in one place is ideal.
               objectPool.push(clipItem);
             }

There you go! You have plotted your clips around a predefined center and radius constant;

Move The Items? Follow the same logic of finding the x and y at small increments ..say angle should be increased at each execution by 1. you could do this in either a TimerEvent.TIMER/Event.ENTER_FRAME event listeners to calculate new position and update clips' positions.

Hope that helps. Thanks

Upvotes: 1

Related Questions