本文介绍了Android OBB/ZIP 加载 (cocos2dx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在处理 APK 扩展时遇到了问题.在 Java 方面,我可以设置我应该设置的所有内容,但似乎我无法在 c++ 方面正确修改代码.

I have a problem dealing with the APK expansions. On Java side, I could set up everything I supposed to set, but it seems I can't modify the code properly on c++ side.

CCFileUtilsAndroid::getFileData 函数内部:

Inside the CCFileUtilsAndroid::getFileData function:

if (fullPath[0] != '/')
{
   CCLOG("GETTING FILE RELATIVE DATA: %s", fullPath.c_str());
   pData  = CCFileUtils::sharedFileUtils()->getFileDataFromZip("/storage/sdcard0/Android/obb/com.example.package/main.1.com.example_package.obb", fullPath.c_str(), pSize);
}

但是 pData 变量始终为空(如果我是对的,这意味着它无法加载).我想念什么?

But the pData var is always null (if I'm right, this means that it failed to load). What am I missing guys?

在此先感谢

(ps:包在那里,我用对了路径)

(ps: the package is there, and I'm using the right path)

推荐答案

所以,我终于设法解决了我的问题,而且比我想象的要容易得多.我没有使用 c++ 源代码修改,而是在 Cocos2dxHelper java 类中找到了一个函数,即 nativeSetApkPath.查了一下使用,原来是Cocos2dx把apk包处理成一个zip文件.因为我的 obb 毕竟只是一个重命名的 zip 文件,所以我可以毫无问题地使用它.我所有的资产都加载得很好,除了声音.这需要另一个快速修复.

So, I finally managed to resolve my issue, and it was way easier than I thought.Instead of going with the c++ source modifications, I found a function in the Cocos2dxHelper java class which is the nativeSetApkPath. After investigating the use of it, it turned out that Cocos2dx handles the apk package as a zip file. Since my obb is just a renamed zip file after all, I could use it without any problem. All of my assets were loaded fine, except the sounds. Which requires another quick fix.

大部分功劳归功于论坛帖子(http://www.cocos2d-x.org/boards/6/topics/11243) 和 Irwin Billing,因为这是我可以用于修改 Cocos2dxMusic.java 和 Cocos2dxSound.java 类的基础.

Most of the credit goes to a forum post (http://www.cocos2d-x.org/boards/6/topics/11243) and to Irwin Billing, since that was a base I could use for my modifications in the Cocos2dxMusic.java and Cocos2dxSound.java classes.

另外,我必须确保声音资产没有被压缩到 zip 文件中(根据 Google 提供的文档).

Also, I had to be sure that the sound assets were not compressed in the zip file (according to the documentations provided by Google).

为此,我在我的 Mac 上使用了以下命令:

For that I used the following command on my Mac:

zip -rn .ogg:.mp3:.wav assets.zip assets/

我要提到的最后一件事是文件夹结构.我复制粘贴并压缩了资产文件夹,所以我的 zip 文件中有一个文件夹.太好了,因为 apk 的工作方式相同,我不必再做任何修改.

The last thing I'd like to mention is the folder structure. I copypasted and zipped the assets folder, so I have a folder inside my zip file. Which is great, since the apk works the same way, I had to do no more modifications.

最后是我修改的源文件,只是不要忘记浏览它,并更改一些值Cocos2dxHelper.java:http://pastebin.com/RqeYkTkP

Finally my modified source files, just dont forget to go through it, and change some valuesCocos2dxHelper.java:http://pastebin.com/RqeYkTkP

Cocos2dxMusic.java:http://pastebin.com/RXjwmEyb

Cocos2dxMusic.java:http://pastebin.com/RXjwmEyb

Cocos2dxSound.java:http://pastebin.com/1GfDB6jb

Cocos2dxSound.java:http://pastebin.com/1GfDB6jb

这篇关于Android OBB/ZIP 加载 (cocos2dx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 04:56