【问题标题】:Scale non-retina cocos2d-iphone game to fit on an retina iPad screen缩放非视网膜 cocos2d-iphone 游戏以适应视网膜 iPad 屏幕
【发布时间】:2014-01-13 17:13:12
【问题描述】:

我的cocos2d-iphone 1.0.1游戏应该是通用的。

目前,它已经在非视网膜 iPad 上运行良好。也就是说,没有“2x”按钮可以缩放我的应用程序或任何东西。非视网膜 iPad 使用来自视网膜 iPhone 的 -hd 图形,因此我不必专门为非视网膜 iPad 制作图形。我只需要重新定位我的精灵,但关键是非视网膜 iPad 很好。

现在是 iPad Retina。

首先,我没有 iPad Retina 显卡,只有 -hd iPhone Retina 显卡。

我的目的是让视网膜 iPad 像非视网膜 iPad 一样显示游戏 - 也就是说,简单地缩放游戏(图形仍然看起来不错)。

我想到的第一件事就是修改导演。当您替换或推送场景时,场景将获得 2.0 的比例。

虽然这确实会缩放所有游戏图形,但存在位置问题。基本上,如果您在屏幕底部有一个精灵,那么缩放场景后它根本不会出现在屏幕中,因为缩放会将其推到底部。

我非常想模拟 iPad 运行 iPhone 应用程序时出现的“2x”按钮的功能。在这种情况下,从技术上讲,我希望视网膜 iPad 看起来与非视网膜 iPad 完全一样。

我怎样才能做到这一点?

【问题讨论】:

  • 阅读周围我注意到有人说 1.0.1 不支持 iPad Retina。我认为这只有在我有 iPad Retina 显卡的情况下才重要,但我没有,所以我想使用 1.0.1 仍然可以。
  • 无论您采用哪种方式,都会遇到缩放问题(偏移量和字体),但它对我有用。我没有在视网膜 ipad 上启用视网膜 :) 并使用我的 -hd 纹理。另外对于背景纹理,我系统地使用 1136x768 图片......它们适用于所有设备(在 3.5 iPhone 和 iPad 上裁剪)。唯一需要注意的是,如果您想要一个具有“边框”功能的背景纹理,则每种设备类型都需要一个,并且在运行时有一些“if”语句来选择合适的纹理。
  • @YvesLeBorg:“不要启用 Retina 模式” - 先生,我现在感觉非常愚蠢。我完全忘记了您可以启用/禁用它。请给出答案。
  • 请记住,Apple 要求应用支持 Retina 分辨率,这可能意味着如果 Retina iPad 上的图像质量看起来“太模糊”,应用可能会被拒绝。
  • @LearnCocos2D :可能,但我尝试的一些东西与我用我的 -hd 东西得到的渲染并不接近。正如某个 Stefen 不久前指出的那样,苹果真的会检查除“苹果品牌正确性”之外的任何东西吗?我很快就会知道,即将推出游戏:)

标签: ios iphone ipad cocos2d-iphone retina-display


【解决方案1】:

无论您采用哪种方式,都会遇到缩放问题(偏移量和字体),但它对我有用。我没有在视网膜 ipad 上启用视网膜 :) 并使用我的 -hd 纹理。另外对于背景纹理,我系统地使用 1136x768 图片......它们适用于所有设备(在 3.5 iPhone 和 iPad 上裁剪)。唯一需要注意的是,如果您想要一个具有“边框”功能的背景纹理,则每种设备类型都需要一个,并且在运行时有一些“if”语句来选择合适的纹理。

这是我的 AppController 启动

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    [director_ enableRetinaDisplay:NO];
    MPLOG(@"iPad device detected : forcing non-retina !");
    [constants setAsIpad];
    isIpadDevice = YES;
}
else {
    isIpadDevice = NO;
    if (![director_ enableRetinaDisplay:YES]) {
        MPLOG(@"Retina Display Not supported");
    }
    else {
        CGSize portrait  = [CCDirector sharedDirector].winSize;
        CGSize landscape = CGSizeMake(portrait.height, portrait.width);
        if (landscape.width >= 568.) {
            [constants setAsIphoneIpodTall];
        } else {
            [constants setAsIphoneIpodSmall];
        }
    }
}

MPLOG(@"Retina display   : %@", NSStringFromBool(kIsRetina));
MPLOG(@"Scale factor     : %.0f", director_.contentScaleFactor);
MPLOG(@"Screen size      : {%.0f, %.0f}", kScreenWidth, kScreenHeight);
MPLOG(@"Tile size        : {%.0f, %.0f}", kTileWidth, kTileHeight);
MPLOG(@"Battle mid point : %@", NSStringFromCGPoint(kBattleMidPoint));
MPLOG(@"Menu width       : %4i", kMapRightMenuWidth);

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices


// 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];

if (deviceTypeIpodTall == kDeviceType) {

    [GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    MPLOG(@"Pixel resolution : RGBA8888") ;

}
else {
    if (isIpadDevice) {
        [GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
        MPLOG(@"Pixel resolution : RGBA8888") ;
    }
    else {
        [GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
        MPLOG(@"Pixel resolution : RGBA4444") ;
    }

}
[GESprite defaultPixelFormat];

// 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.
// On iPad HD  : "-ipadhd", "-ipad",  "-hd"
// On iPad     : "-ipad", "-hd"
// On iPhone HD: "-hd"
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-hd"];                     // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-hd"];        // Default on iPad RetinaDisplay is "-ipadhd"

// Assume that PVR images have premultiplied alpha

[CCTexture2D PVRImagesHavePremultipliedAlpha:NO];

在“常数”中(哈哈哈)

+(void)setAsIpad {

kDeviceType          = deviceTypeIpadNormal;
kIsIpad              = YES;
kIsIphoneIpod        = NO;
kIsIphoneIpodTall    = NO;
kMapRightMenuWidth   = 0;
kMapBottomMenuHeight = 0;
kTileHeight          = 80.;
kTileWidth           = 80.;
kScreenWidth         = 1024;
kScreenHeight        = 768;
kIsRetina            = NO;
kScreenSize          = CGSizeMake(kScreenWidth, kScreenHeight);
kScreenMidPoint      = ccp(kScreenWidth / 2, kScreenHeight / 2);
kMidScreen           = kScreenMidPoint;
kBattleMidPoint      = ccp(kScreenWidth / 2 - kMapRightMenuWidth / 2, kScreenMidPoint.y);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多