Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Changing the processing using the platform


You can make the program run on specific parts of the source code for each OS. For example, you will change the file name, the file path, or the image scale by the platform. In this recipe, we will introduce the branching code based on the platform of choice in the case of a complication.

How to do it...

You can change the processing by using the preprocessor as follows:

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 
    CCLOG("this platform is Android"); 
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) 
    CCLOG("this platform is iOS"); 
#else 
    CCLOG("this platfomr is others");
#endif

How it works...

Cocos2d-x defined the CC_TARGET_PLATFORM value in CCPlatformConfig.h. If your game is compiled for Android devices, CC_TARGET_PLATFORM is equal to CC_PLATFORM_ANDROID. If it is compiled for iOS devices, CC_TARGET_PLATFORM is equal to CC_PLATFORM_IOS. Needless to say, there are other values besides Android and iOS. Please check CCPlatformConfig.h.

There...