0

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];
iamruskie
  • 766
  • 4
  • 9
  • 22

1 Answers1

1

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.

Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
  • Yea but I but i would have to name each child differently. Is there a cleaner way to do it? – iamruskie Oct 23 '12 at 05:43
  • You could loop through the children of your CCMenu and apply actions to each one. – Ben Trengrove Oct 23 '12 at 06:53
  • Okay but how can i add a delay to the loop so each move can occur before next loop is run? – iamruskie Oct 24 '12 at 04:46
  • You can use the CCDelayTime action in a CCSequence – Ben Trengrove Oct 24 '12 at 04:52
  • You can position the CCMenu at CGPointZero and then the positions of the menuitems will be relative to the scene. I always do something like this `self.themenu = [CCMenu menuWithArray:menuitems]; self.themenu.position = CGPointZero; [self addChild:self.themenu];` – Jonny Aug 27 '13 at 03:21