2

Cocos2d プロジェクトがあり、アプリ全体で一定の背景が必要です。applicationDidFinishLaunchingそのデリゲートのメソッドで、次の行を置き換えました。

[viewController setView:glView];

[[viewController view] addSubview:glView];

initWithNib の RootViewController のビューにサブビューを追加したため、ビューが glView に置き換えられると、これらの変更が失われます。

また、glView の pixelFormat を からkEAGLColorFormatRGB565に変更しましたkEAGLColorFormatRGBA8。その変更を行うと、glView が透明になり、透けて見えるようになりますが、fps が劇的に低下します。その変更を行わないと、ビューは透明になりませんが、fps が大幅に低下することはありません。59.0 ~ 60.0 から約 35.0 ~ 42.0 への fps の大幅な低下について話しています。

上記の addSubview 行のすぐ下にあるこのコードを使用して、ビューを透明にしています。

glClearColor(0, 0, 0, 0);
director.openGLView.backgroundColor = [UIColor clearColor];
director.openGLView.opaque = NO;

最後の 2 行が原因です。それらをコメントアウトすると(1つだけではなく両方)、fpsが大幅に低下しますが、glClearColor行をコメントアウトしてもfpsには影響しません。

applicationDidFinishLaunching メソッド全体は次のようになります。

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

    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;

    // Create the EAGLView manually
    //  1. Create a RGB565 format. Alternative: RGBA8
    //  2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
    //

    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]            
                                   pixelFormat:kEAGLColorFormatRGBA8 
                   depthFormat:0
                       ];

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

    if(![director enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

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

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

    // make the OpenGLView a child of the view controller
    [[viewController view] addSubview:glView];

    //***make glView transparent***
    glClearColor(0, 0, 0, 0);
    director.openGLView.backgroundColor = [UIColor clearColor];
    director.openGLView.opaque = NO;

    // make the View Controller a child of the main window
    [window addSubview:viewController.view];

    [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:kCCTexture2DPixelFormat_RGBA8888];

    // Removes the startup flicker
    [self removeStartupFlicker];

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

なぜこれが起こっているのかについてのアイデアはありますか? 必要に応じて、さらにコードを提供できます。

4

1 に答える 1

0

これを第1世代または第2世代のデバイスでテストしている場合、フレームレートの低下が予想されます。あなたがそれについてできることは何もありません。これらのデバイスはフィルレートが大幅に制限されており、透過的な32ビットGLビューはデバイスに要求しすぎています。

これが第3世代または第4世代のデバイスで発生した場合は、何か問題があるはずですが、それが何であるかを理解することはできませんでした。

シミュレータでパフォーマンスをテストしている場合は、テストしないでください。それは無関係です。

于 2012-01-05T17:00:28.000 に答える