我在 Resources 文件夹中创建了名为“menu_images”的文件夹,其中存储了我的游戏菜单图像。 我的问题: 我必须在 iPhone 和 android 中以两种不同的方式创建 CCSprite 对象。 在 iPhone 中,我可以通过 create() 函数中的“menu_item.png”传递文件名。 但在 Android 中,我必须在 create() 函数中传递“menu_images/menu_item.png”。这在 iPhone 中不起作用。
我想在两个平台上使用相同的代码。有人请帮我解决这个问题。谢谢。
最佳答案
只需在您的 AppDelegate 中为 Resources 中的所有子文件夹设置搜索路径。您可以引用下面的示例代码。
CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = fileUtils->getSearchPaths();
searchPaths.insert(searchPaths.begin(), "menu_images");
fileUtils->setSearchPaths(searchPaths);
设置搜索路径后,您可以加载任何 Sprite 或文件,如:
CCSprite* background = CCSprite::create("menu_item.png")
关于android - 在 cocos2dx 中加载资源,它适用于 android 和 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20455801/