How to write target platform specific code?

hi,
I am trying to write code that will selectively execute for a specific target platform like android or iOS. I tried :

if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) {
my code;
}
however the above doesn’t work. I am using ts/js on creator.
thanks in advance!

Hi, @rsamrry. Did you try cc.sys.platform?

if (cc.sys.platform == cc.sys.ANDROID)
{
    //my specific code is here
}

You can read more about this class here: https://docs.cocos2d-x.org/creator/api/en/classes/sys.html?h=sys

1 Like