zoukankan      html  css  js  c++  java
  • cocos2d-x 2.0.3 设置高清模式注意事项(已移除-hd方式)

    猴子原创,欢迎转载。转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢!

    原文地址: http://www.cocos2dev.com/?p=304

    在cocos2d-x 2.x版本中,iphone设备设置Retina高清模式已经不是原来的在高清图后面加-hd后缀了。2.x以前开启高清模式之后,底层会在addImage的时候自动在图片名称后面加-hd,优先加载-hd的图片,没有-hd的话,在加载原始图。(ipad是-ipad,ipad高清是-ipadhd)。2.0.3已经移除了这个模式(好像是2.0.2就改了),2.x之后将文件管理写成了一个共享单例类:CCFileUtils::sharedFileUtils();在加载图片的时候,会根据图片名称优先在getResourceDirectory()这里找资源,没有的话去resource目录下找。

    比如:程序开始时候,我们设置

    CCFileUtils::sharedFileUtils()->setResourceDirectory(“HD”);

    那么所有的加载图片都会优先在 resource/HD 这个目录下面找,没有的话在resource目录找。所以在开启Retina高清模式的时候就不能用以前的方式把高清图加后缀-hd,而是应该在resource目录下,新建一个目录专门放高清图。

    在AppDelegate中,开启高清模式,并设置优先寻找图片目录为resource/HD。

    pDirector->enableRetinaDisplay(true);

    在2.1版本,已经去掉了手动开启retina了,改为默认开启。如果要使项目完美支持retina, 用setDesignResolutionSize(640, 960, kResolutionExactFit)较简单

    CCFileUtils::sharedFileUtils()->setResourceDirectory(“HD”);

    vector<string> searchPaths;
    searchPaths.push_back("HD");
    CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);

    然后把高清的图放在resource/HD的目录下就可以了,不需要加后缀-hd。

    在这里也可以获取设备信息,根据不同设备设置不同的目录。当然如果不想把高清图放在resource也是可以的。

    比如:CCFileUtils::sharedFileUtils()->setResourceDirectory(“../HD”);

    这样HD应该是和resource处于同级目录下。

    资源文件名重复怎么办?

    because Apple uses virtual paths, all the resources are copied to the root of this folder. So if you have multiple resources of the same name, which the setResourceDirectory method requires, when xcode deploys to the simulator it

    will copy one file and then copy the second over the first.
    The solution is to remove the folder referenced by setResourceDirectory from the project and re-add it; but when you add the resources select: "Create folder references for any added folders".

  • 相关阅读:
    oracle查询哪些sp修改了某些表
    asp.net mvc
    更新计算机驱动
    instr函数的用法
    UNION ALL UNION
    Python机器学习ch02 代码学习2
    Python机器学习 ch02代码学习1
    转载Python切片(小知识点)
    FMCW部分资料连接
    Python基础25 异常堆栈跟踪,释放资源,自定义异常和主动抛出
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3208377.html
Copyright © 2011-2022 走看看