我有一个 Cocos2d 项目,我想在整个应用程序中保持不变的背景。在applicationDidFinishLaunching
其委托的方法中,我替换了以下行:
我已将 glView 的 pixelFormat 从更改kEAGLColorFormatRGB565
为kEAGLColorFormatRGBA8
. 当我进行更改时,glView 变得透明并且我可以看穿它,但是 fps 急剧下降。如果我不进行更改,则视图不会变得透明,但我看不到 fps 的大幅下降。我说的是 fps 的显着下降,从 59.0-60.0 下降到大约 35.0-42.0。
我在上面的 addSubview 行下方使用此代码来使视图透明:
director.openGLView.opaque = NO;
整个 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;
//
// 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 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
// attach the openglView to the director
[director setOpenGLView:glView];
glView.opaque = NO;
// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
//
// VERY IMPORTANT:
// If the rotation is going to be controlled by a UIViewController
// then the device orientation should be "Portrait".
//
// IMPORTANT:
// By default, this template only supports Landscape orientations.
// Edit the RootViewController.m file to edit the supported orientations.
//
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
[director setAnimationInterval:1.0/60];
[director setDisplayFPS:YES];
// make the OpenGLView a child of the view controller
[viewController setView:glView];
//Required in iOS6, recommended in 4 and 5
[window setRootViewController:viewController];
// make the View Controller a child of the main window, needed for iOS 4 and 5
[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: [Intro scene]];
}
关于为什么会发生这种情况的任何想法?如果需要,我可以提供更多代码。
我忘了提及我所做的另一项代码更改。在 CCDirector.m 中setGLDefaultValues
,我更改了这一行:
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
对此:
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);