Actionscript 3 反向循环滚动背景动作脚本

Actionscript 3 反向循环滚动背景动作脚本,actionscript-3,flash,Actionscript 3,Flash,我正在尝试使用actionscript反转flash中滚动背景的方向 我想如果我只是把BG1.y-=10改成BG1.y+=10就行了,但是它似乎打破了if语句,而且backgound不再循环 谁能告诉我哪里出了问题 function scroll(evt:Event):void { BG1.y-=10; BG2.y-=10; if(currentBG.y<-currentBG.height) {

我正在尝试使用actionscript反转flash中滚动背景的方向

我想如果我只是把
BG1.y-=10
改成
BG1.y+=10
就行了,但是它似乎打破了
if
语句,而且backgound不再循环

谁能告诉我哪里出了问题

function scroll(evt:Event):void
       {
        BG1.y-=10;
        BG2.y-=10;
        if(currentBG.y<-currentBG.height)
           {
               if(currentBG==BG1)
               {
                   BG1.y=BG2.y+BG2.height;
                   currentBG=BG2;
               }
               else
               {
                   BG2.y=BG1.y+BG1.height;
                   currentBG=BG1;
               }
           }
    }
功能滚动(evt:事件):无效
{
BG1.y-=10;
BG2.y-=10;

如果(currentBG.y如果将迭代更改为10的正增量,则假设if语句将不再工作,这是正确的。要更新if语句以处理这两种情况,只需确定滚动方向并进行相应调整。因此,您可以创建一个变量,如@Rajneesh所示完成,但以不同的方式实现if语句。下面是它的样子:

private function scroll( e:Event ):void {
    BG1.y += scrollSpeed;
    BG2.y += scrollSpeed;

    if ( currentBG.y < -currentBG.height && scrollSpeed < 0 ) {
        currentBG.y += currentBG.height;
        currentBG = currentBG == BG2 ? BG1 : BG2;
    }
    else if ( currentBG.y >= currentBG.height && scrollSpeed > 0 ) {
        currentBG.y -= currentBG.height;
        currentBG = currentBG == BG2 ? BG1 : BG2;
    }
}
我们已确定正在朝负方向滚动,应相应调整
当前bg
y值。否则

else if ( currentBG.y >= currentBG.height && scrollSpeed > 0 )
我们正向滚动,应该重新定位当前BG,减去其高度

如果您不熟悉语句中的三元运算

currentBG = currentBG == BG2 ? BG1 : BG2;
这与if/else语句的含义相同:

if ( currentBG == BG1 ) {
    currentBG = BG2;
} else {
    currentBG = BG1;
}

我没有看到制作这个滚动条的代码。是否有一个回车框循环在驱动它?你能显示更多的代码吗?
if ( currentBG == BG1 ) {
    currentBG = BG2;
} else {
    currentBG = BG1;
}