2011-07-22 57 views
1

所以在CCLayer中,我添加了一个ImagePicker/Camera到openGLView,然后是一个UIButton - 都很好,但现在我想添加一个CCLabel(以及将来的CCSprites)这些元素的顶部。在openGLView中添加一个CCLabel ontop - cocos2d iphone

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 

回答

1

您需要addSubview UIView的组件openGLView下,如下,

[[[CCDirector sharedDirector] openGLView].superview addSubview:arrowButton]; 

然后,openGLView应该是透明的。 “Displaying an EAGLView with transparent background on a UIImageView

编辑:

移动上的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

+0

对不起,我想要的是在UIImagePickerController顶部显示标签 - 移动UIImagePickerController顶部的Cocos – daidai

+0

好吧,我更新了我的答案。 –

+0

感谢您的帮助,但它没有显示科科斯元素 - 我有[CCDirector sharedDirector] .openGLView.backgroundColor = [UIColor clearColor]; [CCDirector sharedDirector] .openGLView.opaque = NO; glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);并添加了[[[CCDirector sharedDirector] openGLView] .superview addSubview:uip.view]; [[[CCDirector sharedDirector] openGLView] removeFromSuperview]; [uip.cameraOverlayView addSubview:[[CCDirector sharedDirector] openGLView]]; – daidai