如何在圆形轨道上对齐movieClips?

时间:2014-01-07 08:04:43

标签: actionscript-3

as3中的动画片段的圆形对齐? 我在以循环方式移动和对齐动画片段时遇到问题

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();

1 个答案:

答案 0 :(得分:1)

使用三角方程将MovieClip相对于中心定位。

<强>解决方案

          //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);
             }
你去吧!您已经围绕预定义的中心和半径常量绘制了剪辑;

移动物品?遵循以小增量查找x和y的相同逻辑。每次执行时应增加1个角度。您可以在TimerEvent.TIMER / Event.ENTER_FRAME事件侦听器中执行此操作以计算新位置并更新剪辑位置。

希望有所帮助。谢谢