1

Cocos2D の機能以外の理由で、Cocos2D を透明にし、その背後にある UIView を表示する必要がありました。

これは、特定の状況を除いて正常に機能します。スプライトの不透明度がより透明になると、その下に描画された Cocos2D の他のすべてが何らかの理由で透明になり、UIView が透けて見えます。

ここで最初の画像に示されているのは、山の UIView とその下に表示されている空の Cocos2D で描画された水のタイルです。2 番目の画像は同じですが、Cocos2D では画面全体を半分の不透明度で覆う黒いスプライトがあり、何らかの理由でその下の UIView が透けて見えます。私の例でこれが最も目立つのは、水タイルを通して見える山です。

Cocos2D に透過画像を適用しない

Cocos2D に適用された透過画像

私のデリゲートの applicationDidFinishLaunching コードは次のとおりです。

- (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]];
}

他に何か必要な場合はお知らせください。ありがとうございました。

4

0 に答える 0