所以在CCLayer中我将一个ImagePicker / Camera添加到openGLView然后是一个UIButton - 一切都很好,但现在我想在这些元素之上添加一个CCLabel(以及将来的CCSprites)。
uip = [[UIImagePickerController alloc] init];
uip.sourceType = UIImagePickerControllerSourceTypeCamera;
uip.showsCameraControls = NO;
uip.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
答案 0 :(得分:1)
您需要在openGLView下添加子视图UIView组件,如下所示,
[[[CCDirector sharedDirector] openGLView].superview addSubview:arrowButton];
然后,openGLView应该是透明的。 “Displaying an EAGLView with transparent background on a UIImageView”
修改强>
将Cocos移到UIImagePickerController
之上
好的,下面怎么样? addSubview在UIImagePickerController的cameraOverlayView上的cocos2d视图(openGLView)。
[[[CCDirector sharedDirector] openGLView].superview addSubview:uip.view];
[[[[CCDirector sharedDirector] openGLView] removeFromSuperview];
uip.cameraOverlayView = [[CCDirector sharedDirector] openGLView];
此外,您需要Making Cocos2d Transparent。