-
Book Overview & Buying
-
Table Of Contents
Cocos2d-x cookbook
By :
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.
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");
#endifCocos2d-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.
Change the font size
Change margin width
Change background colour