开发者

how to create menu on any other View in cocos2D

开发者 https://www.devze.com 2023-04-05 06:12 出处:网络
how to create menu on any other View it mean\'s i m created a UIView and i want to add MenuButtonon it. This is my code but it is not working properly.. The UIView is hides the MuneButton..

how to create menu on any other View it mean's i m created a UIView and i want to add MenuButton on it. This is my code but it is not working properly.. The UIView is hides the MuneButton..

    UIView *aview;
    aview = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 300,250)];
   aview.backgro开发者_JAVA百科undColor= [UIColor redColor];
    [[[CCDirector sharedDirector] openGLView] addSubview:aview];


     // Standard method to create a button
     CCMenuItem *menuItem1 = [CCMenuItemImage 
                            itemFromNormalImage:@"Icon.png" selectedImage:@"Icon.png" 
                            target:self selector:@selector(NextButton:)];
    menuItem1.position = ccp(100, 60);
     CCMenu *starMenu = [CCMenu menuWithItems:menuItem1, nil];
      starMenu.position = CGPointZero;

[self addChild:starMenu];

and

     (void) NextButton: (CCMenuItem  *) menuItem
   {
NSLog(@"Button1");
    }

how to add Menu on UIView. I Try with AddSubview removing addChild. And i try aview removing self..


Hope it help to you..

 http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index


When you add a subview to a UIView, you are essentially adding them on top of the view. The cocos layer is always at the bottom. You can add the view to the root view controller, but you'll take a performance hit.

You're going about this in the wrong way anyway. Put your button in a CCLayer subclass with a CCColorLayer background and add that to your running scene. In your case: self.


My Learn Cocos2D book (2nd Edition) has a chapter about UIKit integration that explains how you can place UIKit views in front of and behind the Cocos2D GL view while allowing all views (front views, cocos2d view, back views) to respond to touch events.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号