0

Hi guys!
I'm trying to work with CCMenu class. I've this method:

    -(void)showMenuItems {
    CGSize size = [[CCDirector sharedDirector] winSize];
    [CCMenuItemFont setFontSize:28];
    CCMenuItem *runAlertItem = [CCMenuItemFont itemWithString:@"Show Alert" target:self selector:@selector(showAlert)];
    CCMenuItem *showTwitterPageItem = [CCMenuItemFont itemWithString:@"Twitter" target:self selector:@selector(showWebView)];
    CCMenuItem *showApplePageItem = [CCMenuItemFont itemWithString:@"Apple" block:^(id sender) {
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480.0, 320.0)];
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http:/www.apple.com"]]];
        [[[CCDirector sharedDirector] view] addSubview:webView];
        [self scheduleOnce:@selector(hideWebView) delay:10];
    }];

    mainMenu = [CCMenu menuWithItems:runAlertItem, showTwitterPageItem, showApplePageItem, nil];
    [mainMenu alignItemsVerticallyWithPadding:10];
    mainMenu.position = CGPointMake(size.width / 2, size.height / 2);
    [self addChild:mainMenu];
}

Now, I would like to call this method like so:

    [self scheduleOnce:@selector(showMenuItems) delay:71];

Unfortunately, menu is not appearing.
What I'm doing wrong?

Thanks in advance!

Anatoliy Gatt
  • 2,501
  • 3
  • 26
  • 42

1 Answers1

1

I had run the above code in my system and It works fine.
Because you are using scheduleOnce selector for showing menu, it will appear after 71 seconds.

 [self scheduleOnce:@selector(showMenuItems) delay:71];
jay
  • 3,517
  • 5
  • 26
  • 44
  • exactly, when I runned without this method just with [self showMenuItems], it works fine, but it is appearing in the beginning, I need it to appear when the animation is stopped. – Anatoliy Gatt May 22 '12 at 09:33
  • but it is not appearing after 71 secs. – Anatoliy Gatt May 22 '12 at 09:34
  • @AnatoliyGatt I think the error is not associated with this code. I just added this code in a new cocos2d project and the menu will displayed after 71 secs. – jay May 22 '12 at 09:37
  • @AnatoliyGatt Do u have any other items on the screen other than the menu? If there is more than one item in the Scene, setting the z-index of each item will work. [self addChild:mainMenu z:20]; – jay May 22 '12 at 09:41
  • Yeah, I checked, so there is my mistake. Thank you. I would solve it. – Anatoliy Gatt May 22 '12 at 09:43