Opengl es Cocos2D:openGL es在UIView上变得透明

Opengl es Cocos2D:openGL es在UIView上变得透明,opengl-es,uiview,cocos2d-iphone,opacity,transparent,Opengl Es,Uiview,Cocos2d Iphone,Opacity,Transparent,出于Cocos2D功能之外的原因,我需要使其透明并显示UIView的背后 除非在特定情况下,否则此操作正常。当精灵的不透明度变得更透明时,它会使在其下绘制的Cocos2D中的所有其他内容变得透明,这是由于某种原因,使我的UIView显示出来 第一幅图上显示的是水彩画,用Cocos2D绘制,可以看到山和山下的天空。第二幅图像是相同的,除了在Cocos2D中,有一个黑色精灵以半透明度覆盖了整个屏幕,出于某种原因,这使得它下面的UIView显示出来。在我的例子中,这是最明显的地方,那就是透过水砖看到的

出于Cocos2D功能之外的原因,我需要使其透明并显示UIView的背后

除非在特定情况下,否则此操作正常。当精灵的不透明度变得更透明时,它会使在其下绘制的Cocos2D中的所有其他内容变得透明,这是由于某种原因,使我的UIView显示出来

第一幅图上显示的是水彩画,用Cocos2D绘制,可以看到山和山下的天空。第二幅图像是相同的,除了在Cocos2D中,有一个黑色精灵以半透明度覆盖了整个屏幕,出于某种原因,这使得它下面的UIView显示出来。在我的例子中,这是最明显的地方,那就是透过水砖看到的山

我的代理人的ApplicationIDFinishLaunching代码如下:

- (void) applicationDidFinishLaunching:(UIApplication*)application 
{
    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Try to use CADisplayLink director
    // if it fails (SDK < 3.1) use the default director
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];


    CCDirector *director = [CCDirector sharedDirector];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGBA8    // kEAGLColorFormatRGBA8, kEAGLColorFormatRGB565
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

    // attach the openglView to the director
    [director setOpenGLView:glView];

    glView.opaque = NO;

#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:YES];


    //color/gradient BG

    bgLayer = [ColorBGView createGradientWithName:@"darkCave"];

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    bgLayer.frame = CGRectMake(0, 0, screenHeight, screenWidth);
    [viewController.view.layer insertSublayer:bgLayer atIndex:0];


    // add custom parallax view

    parallaxView = [[ParallaxView alloc] init];
    parallaxView.frame = CGRectMake(0, 0, 1024, 768);
    [viewController.view insertSubview:parallaxView atIndex:1];

    [parallaxView release];


    // make the OpenGLView a child of the view controller
    [viewController.view insertSubview:glView atIndex:2];
    viewController.view.opaque = YES;
    viewController.view.backgroundColor = [UIColor blackColor];


    // make the View Controllers childs of the main window
    window.rootViewController = viewController;


    foregroundLabelView = [[ForegroundLabelView alloc] init];
    foregroundLabelView.frame = CGRectMake(0, 0, 1024, 768);
    [viewController.view insertSubview:foregroundLabelView atIndex:3];
    foregroundLabelView.hidden = YES;

    [foregroundLabelView release];


    [window makeKeyAndVisible];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888]; //

    [glView setMultipleTouchEnabled:YES];


    // Removes the startup flicker
    [self removeStartupFlicker];

    // Run the intro Scene
    [[CCDirector sharedDirector] runWithScene: [BlankScene scene]];
}

如果你还需要什么,请告诉我。谢谢。

Cocos2D功能之外的原因我已经为这款游戏工作了一年半,Cocos2D的大部分内容都经过了大量编辑。我可能会采用许多更新,但现在我发现这是不必要的。我在下面使用UIView的部分原因是为了在场景转换时有平滑的滚动视差背景。否则,如果我使用Cocos2D的视差BG,当场景转换发生时,一个新的视差会出现在另一个视差BG的上方,并且不同步。嗯,我看不出在哪里设置glClearColor,这可能是问题所在。应该都是0。更改叠加精灵的blendFunc也可能会有所启示。谢谢,我应该把它放在哪里?哦,我从相当简单的屏幕截图推断它一定是一个新项目为了解决场景改变的问题,我不会简单地改变场景,而是将动画层移入移出,在整个游戏中保留背景滚动的场景。