限制给定边界内的动画片段移动

时间:2014-11-13 15:15:19

标签: flash actionscript-2 movieclip

我正在为我的项目使用ActionScript 2.0。我有一个沿x轴移动的影片剪辑。我的问题是,我不知道如何限制给定边界上的影片剪辑,因为它会不断移动。

这是我的代码:

onClipEvent (enterFrame) {
    speed = 1;
    this._x -= speed;
}

1 个答案:

答案 0 :(得分:0)

onClipEvent (load) {
    speed = 1;
    boundary = 100; 
}

onClipEvent (enterFrame) {
    if (this._x > boundary) {
        this._x -= speed;
    } else {
        this._x = boundary;
        delete this.onEnterFrame;
    }
}

备注:您应该直接在时间轴上编写代码:

var speed:Number = 1;
var boundary:Number = 100;

this.onEnterFrame = function():Void {
    if (clip._x > boundary) {
        clip._x -= speed;
    } else {
        clip._x = boundary;
        delete this.onEnterFrame;
    }
}