Cocos2d-x v2.1 中 setResourceDirectory() 方法不再可用

2024-06-10 12:18

本文主要是介绍Cocos2d-x v2.1 中 setResourceDirectory() 方法不再可用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文链接:http://blog.csdn.net/some_do/article/details/8914748

cocos2d-x v2.1 中不支持 CCFileUtils::sharedFileUtils()->setResourceDirectory(dir) 方法,

替代的做法是使用 CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders)方法,

resDirOrders 声明为 std::vector<std::string> 。

cocos2d-x 文档中描述如下(英文的,简单明了,偷懒不翻译了):


1.1. Developer guilde

CCFileUtils::setSearchResolutionsOrder() is added to support distributed strategy. 

You can set searching resolutions order like this

using namespace std;
vector<string> resDirOrders;
if (resolution is ipad retina) {resDirOrders.push_back("resources-ipadhd");resDirOrders.push_back("resources-ipad");resDirOrders.push_back("resources-iphonehd");
}
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);

After setting searching resolutions order, suppose we create a sprite like this

CCSprite* sprite = CCSprite::create("images/tex.png"); 

Engine will find tex.png in the following sequence

find it in images/resources-ipadhd/

if not found, find it in images/resources-ipad/

if not found, find it in images/resources-iphonehd/

if not found, find it in images/


1.2. Notes

This strategy is not suitable for multi-resolution adaption, because there are too many resolutions on Android. 

You can not provide all resources for all resolutions, then set searching order based on resolutions, such as

using namespace std;
vector<string> resDirOrders;
if (resolution is reslution1) {resDirOrders->push_back("path1");resDirOrders->push_back("path2");...
} else if (resolution is resolution2) {resDirOrders->push_back("path-a");resDirOrders->push_back("path-b");...
}
...
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders);

2. Centralized strategy

2.1. Why use a different mechanism than cocos2d-iphone

Cocos2d-iphone uses -hd, -ipad, -ipadhd to determine which picture to load. 

This mechanism is good enough for iOS platform, 

but is not so suitable for Android, because it has many different resolutions.

Cocos2d-x is a cross platform engine, so it should use another mechanism.


2.2. What is the new mechanism

Cocos2d-x uses the new mechanism to load a picture since version cocos2d-2.0-x-2.0.2. 

It does not use -hd, -ipad, -ipadhd suffixes to indicate images for different resolutions.

The mechanism is:

Try to find a picture in the paths set by CCFileUtils::setSearchPaths() firstly,

if it's not found, then find the picture in Resources/

// set searching paths to "/mnt/sd/example" and "/data/data/org.cocos2dx.example" 
vector<string> searchPaths;
searchPaths.push_back("/mnt/sd/example");
searchPaths.push_back("/data/data/org.cocos2dx.example");
CCFileUtils::setSearchPaths(searchPaths);
// engine will find "1.png" in /mnt/sd/example, if there it is not found, 
// then engine will find "1.png" in /data/data/org.cocos2dx.example
// if not found, engine will find "1.png" in Resources/ (this path is platform dependent)
CCSprite* pSprite = CCSprite::create("1.png");

It is easy to add searching path to engine. 

Using this method, you can load resources into a path you know, then set this path to engine. 

Engine will find a resource in this path if needed.


2.3. Developer guide

Do not use -hd, -ipad, -ipadhd suffixes any more. 

Instead, put all hd files in a directory, then all ipad files in another directory, and so on, 

then set resource directory to tell the engine where to find a picture.

If you want to share some resources between different resolutions, 

then you can put all shared resources in Resources/, 

and put resolution specified resources in different directories.

You can refer to samples/HelloCpp for more information.


这篇关于Cocos2d-x v2.1 中 setResourceDirectory() 方法不再可用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1048141

相关文章

Python函数返回多个值的多种方法小结

《Python函数返回多个值的多种方法小结》在Python中,函数通常用于封装一段代码,使其可以重复调用,有时,我们希望一个函数能够返回多个值,Python提供了几种不同的方法来实现这一点,需要的朋友... 目录一、使用元组(Tuple):二、使用列表(list)三、使用字典(Dictionary)四、 使

Linux查看系统盘和SSD盘的容量、型号及挂载信息的方法

《Linux查看系统盘和SSD盘的容量、型号及挂载信息的方法》在Linux系统中,管理磁盘设备和分区是日常运维工作的重要部分,而lsblk命令是一个强大的工具,它用于列出系统中的块设备(blockde... 目录1. 查看所有磁盘的物理信息方法 1:使用 lsblk(推荐)方法 2:使用 fdisk -l(

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

MySQL查看表的最后一个ID的常见方法

《MySQL查看表的最后一个ID的常见方法》在使用MySQL数据库时,我们经常会遇到需要查看表中最后一个id值的场景,无论是为了调试、数据分析还是其他用途,了解如何快速获取最后一个id都是非常实用的技... 目录背景介绍方法一:使用MAX()函数示例代码解释适用场景方法二:按id降序排序并取第一条示例代码解

Python中合并列表(list)的六种方法小结

《Python中合并列表(list)的六种方法小结》本文主要介绍了Python中合并列表(list)的六种方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录一、直接用 + 合并列表二、用 extend() js方法三、用 zip() 函数交叉合并四、用

Java 中的跨域问题解决方法

《Java中的跨域问题解决方法》跨域问题本质上是浏览器的一种安全机制,与Java本身无关,但Java后端开发者需要理解其来源以便正确解决,下面给大家介绍Java中的跨域问题解决方法,感兴趣的朋友一起... 目录1、Java 中跨域问题的来源1.1. 浏览器同源策略(Same-Origin Policy)1.

Java Stream.reduce()方法操作实际案例讲解

《JavaStream.reduce()方法操作实际案例讲解》reduce是JavaStreamAPI中的一个核心操作,用于将流中的元素组合起来产生单个结果,:本文主要介绍JavaStream.... 目录一、reduce的基本概念1. 什么是reduce操作2. reduce方法的三种形式二、reduce

MybatisX快速生成增删改查的方法示例

《MybatisX快速生成增删改查的方法示例》MybatisX是基于IDEA的MyBatis/MyBatis-Plus开发插件,本文主要介绍了MybatisX快速生成增删改查的方法示例,文中通过示例代... 目录1 安装2 基本功能2.1 XML跳转2.2 代码生成2.2.1 生成.xml中的sql语句头2

python3 pip终端出现错误解决的方法详解

《python3pip终端出现错误解决的方法详解》这篇文章主要为大家详细介绍了python3pip如果在终端出现错误该如何解决,文中的示例方法讲解详细,感兴趣的小伙伴可以跟随小编一起了解一下... 目录前言一、查看是否已安装pip二、查看是否添加至环境变量1.查看环境变量是http://www.cppcns

Linux给磁盘扩容(LVM方式)的方法实现

《Linux给磁盘扩容(LVM方式)的方法实现》本文主要介绍了Linux给磁盘扩容(LVM方式)的方法实现,涵盖PV/VG/LV概念及操作步骤,具有一定的参考价值,感兴趣的可以了解一下... 目录1 概念2 实战2.1 相关基础命令2.2 开始给LVM扩容2.3 总结最近测试性能,在本地打数据时,发现磁盘空