Android OBB/ZIP loading (cocos2dx)

跟風遠走 提交于 2019-11-29 02:35:09

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.

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.

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

For that I used the following command on my Mac:

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

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.

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

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

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

Just a side note, I leave ttf font files in assets/, because Cocos2dxTypefaces load them from AssetManager (AKA the apk file) using native codes.

jangyuk

Version 2.x is only my opinion. 3.x is not working Cocos2dxHelper.java is.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!