How to check on which platform game is running?

I have 3 images of different formats (one for ipad, one for iphone, one for android) stored on a server.

Depending on the device’s configuration I should fetch specific image for that device.

How do i check on which platform game is running?

You can use CC_TARGET_PLATFORM macro

What Dredok said. e.g.

#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
  // do something
#endif

Platform definitions are in CCPlatformConfig.h. It doesn’t look like it differentiates between iPhone and iPad though.

You may want to use something like screen resolution to choose if you want iPhone assets or iPad assets, because newer phones have resolutions similar to iPads (I think the iPhone 5 and 6 both have resolutions higher than the iPad 2 and the first iPad Mini) so you may want to use your best images for newer phones. Lower quality images on higher resolution screens might not look great. But that’s up to you.

AppDelegate also has a getTargetPlatform function, which uses the platform definitions in CCApplicationProtocol.h, and actually has iPad and iPhone as 2 separate values, if you do want to separate your assets by device type rather than screen resolution.

2 Likes