0

我在 AS2 中遇到问题,我正在制作一个 Flash 游戏,通过单击一个按钮,您应该能够向上移动一个电影剪辑。这里的问题是我知道该怎么做:

    on(press){
example._y-=10;
}

但我想逐渐向上移动它,就像一个坐标一个坐标直到它达到十,给一点动画。我也不想要任何补间动画,因为影片剪辑已经与其他东西共享代码,所以不要让它变得复杂。我尝试了循环,但效果不佳,这是代码:

on (press) {

    var i = 1;
    while (i < 10)
    {
        _root.example._y-=1;
        i++;
    }
}

我实际上不擅长循环,我只是把它从互联网上取下来。因此,也许您可​​以帮助我纠正循环代码,或者您可以通过使用任何其他技术来帮助我,但无论如何,它一定与补间动画无关,它应该只改变特定的变量影片剪辑。

如果您想要我正在创建的文件,请回复,谢谢!:)

4

1 回答 1

1

If you change the _y property repeatedly in a while loop you will not see the change as an animation (flash will run the code and update the screen when the script has finished, so it will jump to the end position immediately).

Instead, you can change the value on each new frame until the new position has been reached:

on (press) {
    var moveCount = 10;

    _root.example.onEnterFrame = function() {
        moveCount--;

        if (moveCount > 0) {
            this._y--;
        } else {
            delete this.onEnterFrame;
        }
    }
}

Also, it is highly recommended that you don't have a lot of code in the on(press) handler but create a new function and call that instead. Makes it easier to reuse and maintain the code.

于 2013-01-07T14:53:13.697 回答