Adding a CCLabel ontop of openGLView - cocos2d iphone
So within a CCLayer I am adding an ImagePicker / Camera to the openGLView and then a UIButton - all good, but now I want to add a CCLabel (and in the future CCSprites) on top of those elements.
uip = [[UIImagePickerController alloc] init];
uip.sourceType = UIImagePickerControllerSourceTypeCamera;
uip.showsCameraControls = NO;
ui开发者_运维技巧p.toolbarHidden = YES;
uip.navigationBarHidden = YES;
uip.wantsFullScreenLayout = YES;
uip.cameraViewTransform = CGAffineTransformScale(uip.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM);
[[[CCDirector sharedDirector] openGLView] addSubview:uip.view];
arrowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[arrowButton addTarget:self
action:@selector(arrowButtonClicked:)
forControlEvents:UIControlEventTouchUpInside];
UIImage *imgNormal = [UIImage imageNamed:@"btn_next_norm.png"];
[arrowButton setImage:imgNormal forState:UIControlStateNormal];
UIImage *imgPressed = [UIImage imageNamed:@"btn_next_pressed.png"];
[arrowButton setImage:imgPressed forState:UIControlStateHighlighted];
arrowButton.frame = CGRectMake(screenSize.width - 48.0, screenSize.height - 37.0, 48.0, 37.0);
[[[CCDirector sharedDirector] openGLView] addSubview:arrowButton];
CCLabelTTF* label = [CCLabelTTF labelWithString:@"Experience 1" fontName:@"Arial" fontSize:32];
label.color = ccc3(0, 0, 0);
CGSize size = [[CCDirector sharedDirector] winSize];
label.position = CGPointMake(size.width / 2, size.height / 2);
// [[[CCDirector sharedDirector] openGLView] addSubview:labe]; cant add to openGLView
You need to addSubview UIView components under the openGLView as the following,
[[[CCDirector sharedDirector] openGLView].superview addSubview:arrowButton];
And then, openGLView should be transparent. "Displaying an EAGLView with transparent background on a UIImageView"
EDIT:
moving the Cocos on top of the UIImagePickerController
Ok, how about the following? addSubview the cocos2d view (openGLView) on cameraOverlayView of UIImagePickerController.
[[[CCDirector sharedDirector] openGLView].superview addSubview:uip.view];
[[[[CCDirector sharedDirector] openGLView] removeFromSuperview];
uip.cameraOverlayView = [[CCDirector sharedDirector] openGLView];
Also, you need Making Cocos2d Transparent.
精彩评论