0

我想在此处绘制的圆圈之间设置位移。此外,我想将圆圈位置复制到头部圆圈,但偏移量当然会因此而被清除。

public var circles:Vector.<circle> = new Vector.<circle>(5);
        public function t()
        {

        var offset:int = 10;    
        for ( var i:int = 0; i<5; i++)
        {
            var c:circle = new circle();

            c.xPosition= 120+offset;
            c.yPosition = 120;
            c.vx = 1;
            c.vy = 0;
            circles[i] = c;
            offset+=40;


        }
        addEventListener(Event.ENTER_FRAME, gameLoop);

        }

        public function gameLoop(event:Event):void
        {
            for ( var i:int = 0; i<5; i++)
            {
                addChild(circles[i]);
                circles[i].drawCircle(circles[i].xPosition, circles[i].yPosition);
            }


            for ( var i:int = 0; i<5; i++)
            {
                if ( i != 0 )
                {
                circles[i].xPosition = circles[i-1].xPosition;
                circles[i].yPosition = circles[i-1].yPosition;
                }
                else {

                }
            }

            circles[0].xPosition-=circles[0].vx*(2*5);
            circles[0].yPosition-=circles[0].vy*(2*5);

        }
4

1 回答 1

0

从后到前循环。你所做的改变了每个圆圈的位置与圆圈 0 相同

 for ( var i:int = 4; i > 0; i--)
 {   
      circles[i].xPosition = circles[i-1].xPosition;
      circles[i].yPosition = circles[i-1].yPosition;

  }
于 2013-08-30T15:08:32.277 回答