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 的 Moveclip 设置为Background。我想知道如何将背景重置回它在我的函数中的起始位置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 回答