0

ボール クリップに当たったときにフレーム 2 に移動するブリック クリップがあります。このコードはブリック クラス内にあるため、「これ」と呼ばれます。

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

私の質問は、2 回目にヒットしたとき、どうすればフレーム 3 に移動できるかということです。どのコードを追加する必要がありますか?

4

2 に答える 2

0

ブリックの現在のフレームを確認し、フレーム 2の場合は次のようにフレーム 3に移動します。

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

booleanを使用して、レンガがヒットしたかどうかを示すこともできます。の場合true、フレーム 3 に移動します。

編集

AS コード :

- ブール値の使用:

...

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 に答える