我还有一个奇怪的问题,我无法在合理的时间内解决。我的应用程序在启用和未启用视网膜的iPhone 4S和iPod 4-th上运行良好。它在没有视网膜的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];
和菜单场景.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");
}
但问题仍然存在——为什么?
问题解决了。"清洁"是不够的。按下"清洁"时按住"选项"按钮会强制清理更多内容。在那之后,事情开始发挥作用。也有可能它与"压缩PNG文件"设置有关,我在问题开始后将其更改为"否",但可能没有强制执行。无论如何,问题消失了,感谢您观看:)