【问题标题】:How to detect whether I need to use UHD, HD or SD in Cocos2d-x如何在 Cocos2d-x 中检测是否需要使用 UHD、HD 或 SD
【发布时间】:2019-04-02 11:36:10
【问题描述】:

我正在用 Cocos2d-x C++ 制作一个平台游戏。

我想做的事情真的很简单,但是我在互联网上找到的所有内容要么不起作用,要么适用于另一种编程语言,如 Objective-C。

我有 1 个具有 3 个版本的精灵表:一个是 UHD,另一个是 HD,最后一个是 SD

我只需要知道如何告诉程序它应该使用哪些资源。

我试过用这个:

Director::getInstance()->getVisibleSize();
auto winSize = Director::getInstance()->getWinSize(); //gets window size (pretty obvious, isn't it?)

if (&winSize == "2048x1536") { //The device uses UHD graphics
    FileUtils::getInstance()->addSearchResolutionsOrder("UHD");
} else if (&winSize == "1024x768") { //The device uses HD graphics
    FileUtils::getInstance()->addSearchResolutionsOrder("HD");
} else { //any other type of resolution -> asumes it is SD
    FileUtils::getInstance()->addSearchResolutionsOrder("SD");
}

但它只是返回 winSize 对象的内存地址,因此无法使用它。我只需要看看屏幕分辨率是多少,然后设置我需要的图形类型。

对不起,如果这是一个非常愚蠢的问题,我是 C++ 新手,我还没有找到任何关于此的内容。

谢谢

【问题讨论】:

  • 我可以发誓我昨天看过这个标题
  • "hdr" 与分辨率无关。 hdr 表示更大的动态亮度范围。
  • @bolov 是的,我使用了错误的术语。对于 HDR,我的意思是 UHD。

标签: c++ cocos2d-x


【解决方案1】:

const Size& getWinSize ( ) const

以磅为单位返回 OpenGL 视图的大小。

来自https://cocos2d-x.org/reference/native-cpp/V3.0alpha0/d7/df3/classcocos2d_1_1_director.html#aa841a76e9016679ff92bc053e1a41718

大小:https://cocos2d-x.org/reference/native-cpp/V3.0alpha0/d0/d8c/classcocos2d_1_1_size.html

所以我猜,是这样的吗?

auto winSize = Director::getInstance()->getWinSize(); //gets window size (pretty obvious, isn't it?)

if (winSize.width == 2048 and winSize.height == 1536 ) { 
    //The device uses HDR graphics
}

【讨论】:

  • 谢谢。多亏了这一点,我才能知道游戏使用什么图形,但它一直给我以下错误:libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
  • 很高兴它有帮助,这个错误可能与这个问题无关,尝试制作一个最小的工作示例来重现这个错误并打开另一个问题。我很乐意再次为您提供帮助:)
猜你喜欢
  • 2011-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多