iPad 视网膜显示屏上的黑屏

Posted

技术标签:

【中文标题】iPad 视网膜显示屏上的黑屏【英文标题】:Black screen on iPad retina display 【发布时间】:2012-04-25 12:31:06 【问题描述】:

我在 iPad 上运行的一个小游戏应用程序有问题。当我用 iPad 视网膜显示模拟器 ios 5.1 午餐时,应用程序以我的默认图像@x2 开始,显示图像后进入黑屏。在普通 iPad iOS 5.1 模拟器上运行良好。 Xcode 只告诉我这个:

2012-04-25 14:24:26.978 AppName[83696:10a03] cocos2d: Frame interval: 1
2012-04-25 14:24:26.980 AppName[83696:10a03] cocos2d: surface size: 1536x2048

有什么想法吗? 谢谢


@Smamim Hossain:我把完整的 Appdelegate.m 放了同样的错误

#import "cocos2d.h"

#import "AppDelegate.h"
#import "GameConfig.h"
#import "Intro.h"
#import "RootViewController.h"

@implementation AppDelegate

@synthesize window;

- (void) removeStartupFlicker


//#if GAME_AUTOROTATION == kGameAutorotationUIViewController


//#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController  

- (void) applicationDidFinishLaunching:(UIApplication*)application

[director setProjection:kCCDirectorProjection2D]



    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];

    [director setProjection:kCCDirectorProjection2D]
    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:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

//  // 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");


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

    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:NO];
    [director setDepthTest:NO];

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

    // 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: [Intro scene]];



- (void)applicationWillResignActive:(UIApplication *)application 
    [[CCDirector sharedDirector] pause];


- (void)applicationDidBecomeActive:(UIApplication *)application 
    [[CCDirector sharedDirector] resume];


- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application 
    [[CCDirector sharedDirector] purgeCachedData];


-(void) applicationDidEnterBackground:(UIApplication*)application 
    [[CCDirector sharedDirector] stopAnimation];


-(void) applicationWillEnterForeground:(UIApplication*)application 
    [[CCDirector sharedDirector] startAnimation];


- (void)applicationWillTerminate:(UIApplication *)application 
    CCDirector *director = [CCDirector sharedDirector];

    [[director openGLView] removeFromSuperview];

    [viewController release];

    [window release];

    [director end]; 


- (void)applicationSignificantTimeChange:(UIApplication *)application 
    [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];


- (void)dealloc 
    [[CCDirector sharedDirector] end];
    [window release];
    [super dealloc];


@end

【问题讨论】:

你用的是什么版本的cocos2d-iphone? @Halley cocos2d-iphone-2.0-rc1 你能给我更多的细节吗?我必须知道你是如何实现你的场景的,比如它的位置和锚点。另外,您是否在 AppDelegate 中正确启用了视网膜显示? @Halley 在我的 Appdelegate.m 我有这个:if(! [director enableRetinaDisplay:YES]) CCLOG(@"Retina Display Not supported"); 【参考方案1】:

试试这行代码 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:

[导演组投影:kCCDirectorProjection2D];

希望这能解决您的问题。

【讨论】:

谢谢你的帮助,现在我有了这个: - (void) applicationDidFinishLaunching:(UIApplication*)application - (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions: [director setProjection:kCCDirectorProjection2D] 但是显示错误:预期的方法体 - 只需添加这一行 [director setProjection:kCCDirectorProjection2D];在 applicationdidFinishLaunchingWithOptions 方法中 它没有帮助我应该设置它的任何特定位置! 这是最好的解决方案!

以上是关于iPad 视网膜显示屏上的黑屏的主要内容,如果未能解决你的问题,请参考以下文章

iPad 第三代无法显示视网膜图像

带有 Tableview 图形的 iPad 2 模拟器上的问题仅影响非视网膜显示

设备上的黑屏;模拟器工作正常

苹果手表应用程序上的黑屏页面超过一页

为啥视网膜设备上的图标不显示?

MPMoviePlayer 显示稳定的黑屏