【问题标题】:Migrate Cocos2d to latest device support迁移 Cocos2d 到最新的设备支持
【发布时间】:2021-11-15 14:29:08
【问题描述】:

您好,我正在尝试将我非常旧的代码(2011 年)运行到新的 Xcode12。 我可以运行它,但我的偏移量会使 UI 混乱。我的 SCALEX、SCALEY、OFFSETX、OFFSETY 搞得一团糟,因为当时可用的设备只有 iPhone4s 和标准 iPad。 如何将这些更改为今天支持所有设备。 这是我的旧常量。

// 缩放

#define SW ([[CCDirector sharedDirector] winSize].width)
#define SH ([[CCDirector sharedDirector] winSize].height)
#define SCALEX                                  (1600.0f / 3.0f) / 800.0f
#define SCALEY                                  320.0f / 480.0f
#define OFFSETX                                 ((1600.0f / 3.0f) - 480.0f) / 2
#define OFFSETY                                 (320.0f - 320.0f) / 2

【问题讨论】:

    标签: ios objective-c xcode cocos2d-iphone


    【解决方案1】:

    我不太确定 SCALEXOFFSETX 是如何计算的,但似乎 480.0f 和 320.0f 可以替换为

    #define DEVICE_HEIGHT [[[[UIApplication sharedApplication] keyWindow] rootViewController].view convertRect:[[UIScreen mainScreen] bounds] fromView:nil].size.height
    

    #define DEVICE_WIDTH [[[[UIApplication sharedApplication] keyWindow] rootViewController].view convertRect:[[UIScreen mainScreen] bounds] fromView:nil].size.width
    

    最后的表达式是

        #define SCALEX                                  (1600.0f / 3.0f) / 800.0f
        #define SCALEY                                  DEVICE_WIDTH / DEVICE_HEIGHT
        #define OFFSETX                                 ((1600.0f / 3.0f) - DEVICE_HEIGHT) / 2
        #define OFFSETY                                 (DEVICE_WIDTH - DEVICE_WIDTH) / 2
    

    如果它产生更好的结果,请告诉我,如果我们能知道 1600 和 800 值我们可以改进灵魂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2012-07-08
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多