0

私の Background.as には、背景をスクロールする次のコードがあります。

package{

    //Defining the class
    import flash.display.MovieClip;
    import flash.events.Event;

    public class Background extends MovieClip{

        function Background()
        {
            //Executes the enterFrame function
            addEventListener("enterFrame", enterFrame);

        }

        function enterFrame(e:Event)
        {
            this.x -= 1;
        }
    }
}

背景は AS Linkage を に設定した MoveclipBackgroundです。背景を関数内の開始位置にリセットする方法を考えていましたMain.as

4

1 に答える 1

0

変更が適用される前に元の位置を保存し、それを参照できます。

public class Background extends MovieClip
{

    private var _startPosition:Point;


    public function Background()
    {
        _startPosition = new Point(x, y);
        addEventListener(Event.ENTER_FRAME, _enterFrame);
    }


    private function _enterFrame(e:Event):void
    {
        x -= 1;
    }


    public function reset():void
    {
        x = _startPosition.x;
        y = _startPosition.y;
    }

}
于 2013-05-22T03:07:51.863 に答える