Cocos2d iphone Cocos2D HD spriteWithFile以SD显示

Cocos2d iphone Cocos2D HD spriteWithFile以SD显示,cocos2d-iphone,sprite,retina,Cocos2d Iphone,Sprite,Retina,我使用的是CoCoS2D2.1,这个应用程序计划只使用iPad的视网膜和非视网膜。当我使用spriteWithFile并指定不带-hd后缀的文件名时,Cocos2D会找到带-hd后缀的图像并使用它,但它以标准定义显示,这意味着它不会缩小比例,因此显示为视网膜图像 在我的代理的-(BOOL)应用程序:(UIApplication*)应用程序didFinishLaunchingWithOptions:(NSDictionary*)launchOptions方法中,我有以下内容: CCGLView *

我使用的是CoCoS2D2.1,这个应用程序计划只使用iPad的视网膜和非视网膜。当我使用spriteWithFile并指定不带-hd后缀的文件名时,Cocos2D会找到带-hd后缀的图像并使用它,但它以标准定义显示,这意味着它不会缩小比例,因此显示为视网膜图像

在我的代理的-(BOOL)应用程序:(UIApplication*)应用程序didFinishLaunchingWithOptions:(NSDictionary*)launchOptions方法中,我有以下内容:

CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGBA8
                                   depthFormat:GL_DEPTH24_STENCIL8_OES
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

[glView setMultipleTouchEnabled:YES];

director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

[director_ setDisplayStats:YES];

[director_ setAnimationInterval:1.0/60];


// attach the openglView to the director
[director_ setView:glView];

// 2D projection
[director_ setProjection:kCCDirectorProjection2D];

[director_ enableRetinaDisplay:YES];

//  // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director_ enableRetinaDisplay:NO] )
    CCLOG(@"Retina Display Not supported");

// If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used

[sharedFileUtils setiPadRetinaDisplaySuffix:@"-hd"];

glView.opaque = NO;
glClearColor(0.0f,0.0f,0.0f,0.0f);
//glClear(GL_COLOR_BUFFER_BIT);

// Assume that PVR images have premultiplied alpha
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
当我使用spriteWithFile添加精灵(而不是使用精灵工作表,因为它只有一个图像)时,我有以下代码:

movingTileGroup.handleSprite1 = [CCSprite spriteWithFile:@"draggableTileGroupHandle.png"];

movingTileGroup.handleSprite1.position = ccp(x,y);

[self.theMap addChild:movingTileGroup.handleSprite1 z:13];
更新:我看到当调用-(BOOL)enableRetinaDisplay:(BOOL)enabled时,if语句都不会返回true。这可能与比例因子设置有关吗

-(BOOL) enableRetinaDisplay:(BOOL)enabled
{
    NSLog(@"enableRetinaDisplay called");
    // Already enabled ?
    if( enabled && __ccContentScaleFactor == 2 ){
        NSLog(@"enabled && __ccContentScaleFactor == 2 ");
        return YES;
    }

    // Already disabled
    if( ! enabled && __ccContentScaleFactor == 1 ){
        NSLog(@"! enabled && __ccContentScaleFactor == 1 ");
        return YES;
    }

    // setContentScaleFactor is not supported
    if (! [__view respondsToSelector:@selector(setContentScaleFactor:)]){
        NSLog(@"setContentScaleFactor is not supported");
        return NO;
    }
    // SD device
    if ([[UIScreen mainScreen] scale] == 1.0){
        NSLog(@"SD device");
        return NO;
    }

    float newScale = enabled ? 2 : 1;
    [self setContentScaleFactor:newScale];

    // Load Hi-Res FPS label
    [[CCFileUtils sharedFileUtils] buildSearchResolutionsOrder];
    [self createStatsLabel];

    return YES;
}

我假设您正在使用Spritebuilder生成精灵,如果需要在Spritebuilder软件中指定图像的默认大小,可以通过单击显示问题的图像,然后在左侧边栏或面板上选择图像大小作为“默认值”来完成它将自动缩放到所需的大小


如果这不能解决你的问题,一定要让我知道。。。关于…

我使用Zwoptex制作SpriteSheet,但在本例中,我只使用一个png图像,因此不需要SpriteSheet。(这就是我使用spriteWithFile的原因)可能只是要求我使用一个指定宽度和高度的精灵表,这样它才能在视网膜中正确显示。我发现的另一件事是,我无法让视网膜图形在我的主游戏层上与精灵表一起工作,但它们在我的自定义视差层上工作。谢谢你给我一些想法,但我想我会根据这些发现做一个新的线索,然后结束这篇文章。