How to package a resource file in a Cocos2d-wophone into a zip file

Source: Internet
Author: User

Prerequisites

It is assumed that the reader has been able to use cocos2d-wophone for game development and can read resource files from the hard disk. If you still do not know about this, please add relevant knowledge here.

The sample code used in this article, are based on the tests project cocos2d-x source code, in order to read this article can better understand the various operations, it is recommended that you download the cocos2d-x source code, and follow the article on how to run the tests project on WoPhone to run the tests project.

How to operate

It takes only two steps to make your code read the corresponding resource file from the zip file. Take the test wophone project as an example. The steps are as follows:

First, pack all the resource files under the tests/Res Directory into the TestCocos2dx.zip file, and put the file in the specified directory (see the sample code in step 2 ). Here, we do not need to modify the parameters used in the code to use resource files. We need to ensure that the directory structure in the zip file is as follows:

Then add the following code to the applicationDidFinishLaunching function of the AppDelegate class:

1 # if defined (CCX_PLATFORM_WOPHONE)

2 // set the resource zip file

3 CCFileUtils: setResource ("TestCocos2dx.zip ");

4 # endif

Comparison of several resource file reading methods currently supported by cocos2d-wophone

Read Method Advantages Disadvantages
Hard Disk reading The implementation is simple. You only need to call the CCFileUtils: setResource () interface and set the resource file path through the second parameter. 1. It is difficult to package data files when packaging and installing programs;
2. Fully enclosed resource files
Use zip files 1. The implementation is simple. You only need to call the CCFileUtils: setResource () interface to set the name of the zip file through the first parameter;
2. The package and installation procedure is simple. You only need to package the zip file as a data file.
Resource file closed

Call sequence when multiple methods coexist

When multiple resource file reading methods coexist in the Code, the check order is as follows:

「 Read from zip file 」-> 「 read from hard disk 」

Note that when the specified zip file exists, if the resource file to be used cannot be found in the zip file, the resource file will not be searched from the hard disk.

Path for storing WoPhone resource files

Depending on the second parameter value of the CCFileUtils: setResource () function, you need to put the resource file in a different directory. The list is as follows:

Parameter Value Simulator path Real machine path
NULL D:/Work7/NEWPLUS/TG3/APP Same directory as the. so file of the application
Developer-defined directory Developer-defined directory Developer-defined directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.