1

I have 6 menu items on my screen that I want to slide off the screen one by one after the help button (one of the 6 items) is clicked. Here's my code:

NSArray * menuArray = [NSArray arrayWithObjects:item1, item2, item3, item4, item6, item5, nil];
CCDelayTime * delayM = [CCDelayTime actionWithDuration:1.4];
for (CCMenuItem * item in menuArray) {
    id moveLeft = [CCMoveBy actionWithDuration:0.7 position:ccp(10, 0)];
    id moveRight = [CCMoveBy actionWithDuration:0.4 position:ccp(-200, 0)];
    //CCDelayTime * delayM = [[CCDelayTime alloc] initWithDuration:1.4];
    [item runAction:[CCSequence actions:moveLeft, moveRight, delayM, nil]];
}

For some reason, the delay doesn't seem to make any difference here and all of the menu items slide off the screen at the same time. How can I make it so that the menu items won't slide off the screen until the last one already has?

Sidenote: I can't figure out how to cancel all of the selectors that these menu items are hooked up to so that the user won't accidentally touch a selector while this whole animation is going on. Could someone help me with this as well?

4

1 に答える 1

1

これは、それらがすべて同時にこれらのアクションを開始するためです。

これはあなたがそれを行う方法です:

NSArray * menuArray = [NSArray arrayWithObjects:item1, item2, item3, item4, item6, item5, nil];
float delay = 0;
for (CCMenuItem * item in menuArray) {
    CCDelayTime * delayM = [CCDelayTime actionWithDuration:delay];
    id moveLeft = [CCMoveBy actionWithDuration:0.7 position:ccp(10, 0)];
    id moveRight = [CCMoveBy actionWithDuration:0.4 position:ccp(-200, 0)];
    [item runAction:[CCSequence actions:delayM,moveLeft, moveRight,  nil]];
    delay += 1.1;
}

runAction は非同期であることを覚えておいてください。そのため、1 つずつ実行させるには、遅延なしで開始する必要があり、各アイテムについて、前のアイテムのアクションにかかる時間を遅延に追加する必要があります。この場合、すべてのアイテムのアクションには 1.1 秒 (左への移動には 0.7、右への移動には 0.4) かかるため、移動前の遅延をアイテムごとに 1.1 秒延長します。

于 2012-05-27T05:57:34.573 に答える