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

相关文章

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S

MyBatis-Plus 中 nested() 与 and() 方法详解(最佳实践场景)

《MyBatis-Plus中nested()与and()方法详解(最佳实践场景)》在MyBatis-Plus的条件构造器中,nested()和and()都是用于构建复杂查询条件的关键方法,但... 目录MyBATis-Plus 中nested()与and()方法详解一、核心区别对比二、方法详解1.and()

golang中reflect包的常用方法

《golang中reflect包的常用方法》Go反射reflect包提供类型和值方法,用于获取类型信息、访问字段、调用方法等,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录reflect包方法总结类型 (Type) 方法值 (Value) 方法reflect包方法总结

C# 比较两个list 之间元素差异的常用方法

《C#比较两个list之间元素差异的常用方法》:本文主要介绍C#比较两个list之间元素差异,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. 使用Except方法2. 使用Except的逆操作3. 使用LINQ的Join,GroupJoin

MySQL查询JSON数组字段包含特定字符串的方法

《MySQL查询JSON数组字段包含特定字符串的方法》在MySQL数据库中,当某个字段存储的是JSON数组,需要查询数组中包含特定字符串的记录时传统的LIKE语句无法直接使用,下面小编就为大家介绍两种... 目录问题背景解决方案对比1. 精确匹配方案(推荐)2. 模糊匹配方案参数化查询示例使用场景建议性能优

关于集合与数组转换实现方法

《关于集合与数组转换实现方法》:本文主要介绍关于集合与数组转换实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、Arrays.asList()1.1、方法作用1.2、内部实现1.3、修改元素的影响1.4、注意事项2、list.toArray()2.1、方

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四

一文详解Git中分支本地和远程删除的方法

《一文详解Git中分支本地和远程删除的方法》在使用Git进行版本控制的过程中,我们会创建多个分支来进行不同功能的开发,这就容易涉及到如何正确地删除本地分支和远程分支,下面我们就来看看相关的实现方法吧... 目录技术背景实现步骤删除本地分支删除远程www.chinasem.cn分支同步删除信息到其他机器示例步骤

在Golang中实现定时任务的几种高效方法

《在Golang中实现定时任务的几种高效方法》本文将详细介绍在Golang中实现定时任务的几种高效方法,包括time包中的Ticker和Timer、第三方库cron的使用,以及基于channel和go... 目录背景介绍目的和范围预期读者文档结构概述术语表核心概念与联系故事引入核心概念解释核心概念之间的关系

在Linux终端中统计非二进制文件行数的实现方法

《在Linux终端中统计非二进制文件行数的实现方法》在Linux系统中,有时需要统计非二进制文件(如CSV、TXT文件)的行数,而不希望手动打开文件进行查看,例如,在处理大型日志文件、数据文件时,了解... 目录在linux终端中统计非二进制文件的行数技术背景实现步骤1. 使用wc命令2. 使用grep命令