I copied this post from here , which may help answer your question. I believe that it would be better to use cocos2d functions with cocos2d shells, but you can implement with others that it also does not integrate.
If there are any newbies (like me) who need additional help how to integrate the UIKit element with cocos2d, this may help. As you read in the first post of this topic, Blue Ether wrote a wrapper for manipulating UIViews. What is a UIView? Take a look at http://developer.apple.com/iphone/library/documentation/uikit/reference/uikit_framework/Introduction/Introduction.html , scroll down a bit and you will see a diagram of the various UIView elements; such as UIButton, UISlider, UITextView, UILabel, UIAlertView, UITableView, UIWindow, etc. There are more than 20. You can use the Blue Ethas code to wrap any of them inside cocos2d. Here I will end UIButton, but experimenting with your favorite choice of UIView element.
Create a new cocos 2d application project.
Create a new NSObject file and name it CCUIViewWrapper. This will give you the CCUIViewWrapper.h and CCUIViewWrapper.m files. Change (copy them) so that they look like Blue Ether defined them (see the First message in this thread.
Make your HelloWorld.h look like this
// HelloWorldLayer.h #import "cocos2d.h" #import <UIKit/UIKit.h>
and your HelloWorld.m like this
// HelloWorldLayer.m #import "HelloWorldScene.h" // HelloWorld implementation @implementation HelloWorld +(id) scene { CCScene *scene = [CCScene node]; HelloWorld *layer = [HelloWorld node]; [scene addChild: layer]; return scene; } -(void)buttonTapped:(id)sender { NSLog(@"buttonTapped"); } // create and initialize a UIView item with the wrapper -(void)addUIViewItem { // create item programatically button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchDown]; [button setTitle:@"Touch Me" forState:UIControlStateNormal]; button.frame = CGRectMake(0.0, 0.0, 120.0, 40.0); // put a wrappar around it wrapper = [CCUIViewWrapper wrapperForUIView:button]; [self addChild:wrapper]; } -(id) init { if( (self=[super init] )) { [self addUIViewItem]; // x=160=100+120/2, y=240=260-40/2 wrapper.position = ccp(100,260); [wrapper runAction:[CCRotateTo actionWithDuration:4.5 angle:180]]; } return self; } - (void) dealloc { [self removeChild:wrapper cleanup:true]; wrapper = nil; [button release]; button=nil; [super dealloc]; } @end
Build and run. This should trigger a spin button in the middle of the scene. You can touch the button when it rotates. He will write a text message in the console.
source share