Cocos2d-x in win32, android and IOS File Read and Write Problems

Source: Internet
Author: User

Recently learning and using the Cocos2d-x framework, although speaking of cross-platform, but in the Development of VS, and then transplanted to android or IOS, may also have a variety of problems, minor adjustments are required.

For example, when I perform file read/write operations, it is likely that there is no problem on win32, but Get Data Failed on IOS.

After several attempts, we found that the following methods can be used to read data directly in win32, android, and IOS:

 

[Cpp]

# If (CC_TARGET_PLATFORM = CC_PLATFORM_IOS)
Std: string fullPath = CCFileUtils: sharedFileUtils ()-> fullPathFromRelativeFile (filename, foldername );
# Else
Std: string fullPath = CCFileUtils: sharedFileUtils ()-> fullPathForFilename (filename );
# Endif

# If (CC_TARGET_PLATFORM = CC_PLATFORM_IOS)
Std: string fullPath = CCFileUtils: sharedFileUtils ()-> fullPathFromRelativeFile (filename, foldername );
# Else
Std: string fullPath = CCFileUtils: sharedFileUtils ()-> fullPathForFilename (filename );
# Endif

First, if it is an IOS platform, use the fullPathFromRelativeFile method. In this case, filename and the path of its folder are required.

For win32 or android platforms, use fullPathForFilename to obtain the file.

 


Unfortunately, you can use fullPathFromRelativeFile on IOS. You only need the file name first, followed by the folder name. But on win32 and android, filename is the name with the folder path.

Therefore, you need to change the filename based on the platform.

 


However, it is not a big problem to extract the file operations and make adjustments based on the platform judgment.

 

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.