Pros and cons of using CCUIViewWrapper versus ported functionality

I am trying to understand the pros and cons of using something CCUIViewWrapper in Cocos2d compared to ported functionality. For example, it would be better to use a UITableView in CCUIViewWrapper or use CCTableViewSuite. At first glance, I would suggest that a wrapper is a better approach, since apparently this allows me to do everything that a UITableView offers, but is there any key data that I am missing? Are there serious restrictions that exist with the shell, either using the apple sdk object, or the inability to use some functions inside Cocos2d that come with a portable object, such as CCTableView?

+4
source share
2 answers

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> #import "CCUIViewWrapper.h" @interface HelloWorld : CCLayer { UIButton *button; CCUIViewWrapper *wrapper; } +(id) scene; @end 

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.

+2
source

CCUIViewWrapper is not a good solution. I tried and deleted it. The problem is that it wraps the UIKit element in the container and adds it as a director’s view of the main openGL look. One of the problems is that you cannot add any other sprite on top of it. Very limited.

+1
source

All Articles