as3 - 通过不同的位置移动对象

as3 - Moving objects through different positions

我正在使用 as3 在 adobe animate 中编写一个简单的视频游戏。我正在尝试通过 3 个不同位置的滑动动作移动我的对象,例如:

Swipe 1: mc1 moves to 1st position (x = 600; y = 300).
Swipe 2: mc2 moves to 1st position (x = 600; y = 300) and mc1 move to 2nd position (x = 300, y = 300).
Swipe 3: mc3 moves to 1st position (x = 600; y = 300) and mc2 move to 2nd position (x = 300, y = 300) and mc1 moved to 3rd position ((x = -100, y = -100).
Swipe 4: mc4 moves to 1st position (x = 600; y = 300) and mc3 move to 2nd position (x = 300, y = 300) and mc2 moved to 3rd position ((x = -100, y = -100)...and so on. 

我还希望能够 return 通过单击以在任何时候重复整个过程来 return 到循环的开始(滑动 1)。

我正在为我的对象使用数组,例如

var A:Array = 
[ 
mc1,
mc2,
mc3,...mc50
];

我试过这个:

var anObject:DisplayObject;

//move object through swipe action

Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler_1);
function fl_SwipeHandler_1(event:TransformGestureEvent):void
{
    switch(event.offsetX)
    {
        case -1:
    {for each (anObject in A) {
    for (var n:int = 0; n < A.length; n++){

    A[n].x = 600 // how do I get this right?
    A[n].y = 300
    A[n-1].x = 300
    A[n-1].y = 300
    A[n-2].x = -100
    A[n-2].y = -100

    }}

    }   break;
    }

}

//return to beginning of loop (Swipe 1)

mc_return_to_A0.addEventListener(MouseEvent.CLICK, return_to_A0);
function return_to_A0 (event:MouseEvent):void
{n==0} //how do I get this right? ```

Any help would be much appreciated!
Thanks

我无法在手势方面为您提供帮助,因为我从未直接使用过它们,但从逻辑上讲,定位...并不困难。

您有一个 Array 个对象和一个 Array 个位置。第一次滑动后,您只希望第一个对象转到第一个给定位置:

Positions: ...  (6)  (5)  (4)  (3)  (2)  (1)
Objects:                                 (1)  (2)  (3)  (4)  (5)  (6)  ...

第 2 次滑动后:

Positions: ...  (6)  (5)  (4)  (3)  (2)  (1)
Objects:                            (1)  (2)  (3)  (4)  (5)  (6)  ...

第 5 次滑动后:

Positions: ...  (6)  (5)  (4)  (3)  (2)  (1)
Objects:             (1)  (2)  (3)  (4)  (5)  (6)  ...

因此,脚本应如下(类似):

// A list of your objects here.
var A:Array = [mc1, mc2, ... , mc50];

// A list of designated points here. I kinda advise to design
// these on stage with empty MovieClips appropriately named.
// This way you will have a visual representation of these
// positions, not just lots of numbers on your code.
var P:Array = [p1, p2, ... , p50];

// You need to keep a number of successful swipes, it is,
// literally, the number of objects you need to re-position.
var N:int = 0;

// So, after you successfully register a new swipe,
// you call this method to apply the re-positioning.
function arrangeThings():void
{
    // So we take first N objects, one by one.
    for (var i:int = 0; i < N; i++)
    {
        // Figure the index of the P for the current designated position. 
        var anIndex:int = N - i - 1;

        // Get the position object itself.
        var aPos:DisplayObject = P[anIndex];

        // Get the object to position.
        var anObject:DisplayObject = A[i];

        // Assume the designated position.
        anObject.x = aPos.x;
        anObject.y = aPos.y;
    }
}

然后,我已经向您解释了如何重置 中的内容。说白了,你只是在开始时存储初始坐标,然后在需要时重新分配它们。