2011-07-22 59 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