1

quite new to cocos2d so this is probably a school boy question.

I have ccMenu full of ccMenuItemImage's and want to animate each menu item in sequence to fade out.

I have an array with all the CCMenuItemImages:

menuItems = [[NSArray alloc] initWithObjects:button1, button2, button3, nil];

And i am trying to loop through the array and fade each button out:

CCFadeOut *fadeToAlpha = [CCFadeOut actionWithDuration:0.5];

for (CCMenuItemImage *nextOne in menuItems)
    [nextOne runAction:fadeToAlpha];

This seems to work, but will only fade out the last CCMenuItemImage in the array. I know i could perform the action on the actual CCMenu, but i want to perform the animations one after another on each menu item.

Any help would be appreciated.

4

2 回答 2

0

尝试:

int index=0;
for (CCMenuItemImage *nextOne in menuItems){
   CCFadeOut *fadeToAlpha = [CCFadeOut actionWithDuration:0.5]; 
   id fader = [CCSequence actions:[CCDelayTime actionWithDuration:index*.5],
                                  fadeToAlpha,nil];
   [nextOne runAction:fader];
   index++;
}

此外,避免使用具有多个 runAction 的相同动作对象实例,为每个使用实例创建新动作。

于 2012-05-08T03:31:49.653 回答
0

您必须在工作中使用 CCSequence....

而不是使用循环使用 CCSequence 像这样..

[button1 runAction:[CCSequence actions:fadeToAlpha,use CCCallFuncN to call 2nd method, nil]];

第二种方法

[button2 runAction:[CCSequence actions:fadeToAlpha,use CCCallFuncN to call 3nd method, nil]];

.

.

.

.

还有另一种方法......这很棘手......你的淡入淡出时间是 0.5。

float duration = 0;
for (CCMenuItemImage *nextOne in menuItems)
{
    [nextOne runAction:[CCSequence actions:[CCDelayTime actionWithDuraion:duration],fadeToAlpha,nil]];

  value = value + 0.5;

}

检查语法..这样你可以一个接一个地为按钮设置动画......希望这会有所帮助.. :)

于 2012-05-07T19:33:54.400 回答