0

我有一个砖夹,当被球夹击中时会转到第 2 帧。这段代码在砖类中,这就是为什么它被称为“this”的原因:

if (this.hitTestObject(_root.mcBall)){
    _root.ballYSpeed *= -1;
    this.gotoAndStop(2);
}

我的问题是当它第二次被击中时,它怎么能进入第 3 帧?我需要添加什么代码?

4

2 回答 2

1

尝试“干净”的方法,如下所示:

if (this.hitTestObject(_root.mcBall)){
    _root.ballYSpeed *= -1;
    if (this.currentFrame !== 3) {
        this.nextFrame();
    }
}

如果当前帧不是 3,这会使剪辑转到其下一帧。

于 2014-11-01T14:48:10.250 回答
0

您可以验证砖块的当前帧,然后如果是第2帧,则转到第 3 帧,如下所示:

if (this.currentFrame === 2){     
    this.gotoAndStop(3)
}

您还可以使用 aboolean来指示您的砖块是否已被击中。如果true,则转到第 3 帧。

编辑

作为代码:

- 使用布尔值:

...

var hit:Boolean = false

...

if (this.hitTestObject(_root.mcBall)){
    _root.ballYSpeed *= -1
    if(!hit){        // this is the 1st time so set hit to true and go to frame 2
        hit = true
        this.gotoAndStop(2)
    } else {         // this is the 2nd time so go to frame 3
        this.gotoAndStop(3)
    }
}

- 使用 currentFrame :

if (this.hitTestObject(_root.mcBall)){  
    _root.ballYSpeed *= -1  
    if (this.currentFrame == 1){    // we are in the 1st frame so go to frame 2 
        this.gotoAndStop(2)
    } else {                        // we are certainly not in the 1st frame so go to frame 3
        this.gotoAndStop(3)
    }
}

我希望这更清楚。

于 2014-11-01T14:24:33.103 回答