cocos2d-iphoneccmenuitem

CCMenu children transition seperatly


I'm adding CCMenuItems in a loop, and then moving in the CCMenu onscreen with EaseIn. Is there a way to move each CCMenuItem on its own?

CGSize winSize = [[CCDirector sharedDirector] winSize];
CCMenu *chapterMenu = [CCMenu menuWithItems: nil];
 for(int i =1; i<=5; i++){
    CCMenuItem *chapter = [CCMenuItemSprite itemFromNormalSprite:[CCSprite spriteWithFile:@"sprite.png" rect:CGRectMake(0, 0, 150, 210) selectedSprite:nil disabledSprite:nil target:self selector:@selector(OnPlay:)];
    chapter.tag = i;
    [chapterMenu addChild:chapter];
 }
 [chapterMenu alignItemsHorizontallyWithPadding:40];
 chapterMenu.position = ccp(chapterMenu.position.x, chapterMenu.position.y + winSize.height);
 id action = [CCMoveBy actionWithDuration:0.5f position:ccp(0, -winSize.height)];
 id ease = [CCEaseIn actionWithAction:action rate:1.5f];
 [chapterMenu runAction:ease];
 [self addChild:chapterMenu];

Solution

  • You can run actions on the individual menu items as well as they are just subclasses of CCNode.

    Just remember that their position will be relative to the CCMenu, not to your scene.