Working with CCMenu in cocos2d

1.5k views Asked by At

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!

1

There are 1 answers

5
jay On BEST ANSWER

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];