0

我还有一个奇怪的问题,我无法在合理的时间内解决。我的应用程序在 iPhone 4S 和 iPod 4 上运行良好,无论是否启用视网膜。它也适用于没有视网膜的 iPad3。但是当 iPad 启用了视网膜时,CCSprites 就不会出现。我确实有显示的相机图像底层,但上面没有图形。我想我有所有可用的“-hd”版本的文件,它们在 iPhone 上的视网膜模式下也能很好地显示。

我粘贴了我认为相关的代码:

- (void) applicationDidFinishLaunching:(UIApplication*)applicationv{
    CCLOG(@"applicationDidFinishLaunching");

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

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

    CCDirector *director = [CCDirector sharedDirector];

    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

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

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

    // 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:kCCDeviceOrientationLandscapeRight];
#endif

    [director setAnimationInterval:1.0/20];
    [director setDisplayFPS:NO];

    [viewController setView:glView];
    [window addSubview: viewController.view];

    [CCDirector sharedDirector].openGLView.backgroundColor = [UIColor clearColor];
    [CCDirector sharedDirector].openGLView.opaque = NO;

    glClearColor(0.0, 0.0, 0.0, 0.0);

    _cameraView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _cameraView.opaque = NO;
    _cameraView.backgroundColor=[UIColor clearColor];
    [window addSubview:_cameraView];

    _imageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [_cameraView addSubview:_imageView];

    [window bringSubviewToFront:viewController.view];    
    [window makeKeyAndVisible];

    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

    CCScene *scene = [CCScene node];
    _layer =[[[HelloWorldLayer alloc] init] autorelease]; 
    _menu =[MenuScene node]; 
    [scene addChild:_layer];
    [_layer addChild:_menu];
    viewController.fdLayer = _layer;
    _layer.root = viewController;
    [[CCDirector sharedDirector] runWithScene: scene];

和 MenuScene.m:

@implementation MenuScene
+(id) scene {
    CCScene* scene = [CCScene node];
    CCLayer* layer = [MenuScene node];
    [scene addChild:layer];
    return scene;
}

-(id) init {
    if ((self = [super init])) {
        CCLOG(@"init %@", self);

        CGSize screen = [[CCDirector sharedDirector] winSize];
        CCLOG(@"%f %f",screen.width,screen.height);
        CCLayerColor *b = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 100) width:screen.width height:screen.height/4];
        b.isRelativeAnchorPoint=YES;
        b.anchorPoint=ccp(0, 1); // left top corner
        b.position=ccp(0, screen.height);
        [self addChild:b];

        CCSprite* bg = [CCSprite spriteWithFile:@"01-main-logo.png"];
        bg.position = CGPointMake(screen.width / 2, screen.height*0.12);
        [b addChild:bg];

编辑:我做了临时破解:

if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)  {
    // 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");
    }

但问题仍然存在 - 为什么?

4

1 回答 1

0

问题解决了。“清洁”还不够。按下“清理”时按住“选项”按钮会强制清理更多内容。在那之后,事情开始起作用了。也有可能它与“压缩 PNG 文件”设置有关,我在问题开始后将其更改为“否”,但可能未强制执行。无论如何问题消失了,感谢观看:)

于 2012-06-27T03:38:01.673 回答