Cocos2d-x : Wrapper class to communicate with CPP and Objective-C

While developing game for App Store in Cocos2d-X game engine, several times you need to communicate with native Objective-C classes. It is better to create a wrapper class to communicate with Cocos2d-x and Objective-C.

Here I made an example class WrapperCommunicate

// WrapperCommunicate.h

#include <stddef.h>

class WrapperCommunicate
{
public:
static bool checkRetina();

// …

}

// WrapperCommunicate.m

#include “WrapperCommunicate.h”
#import “../cocos2dx/platform/ios/EAGLView.h”
#import <UIKit/UIDevice.h>
#import “RootViewController.h”
#import “Sounds.h”

bool WrapperCommunicate::checkRetina(){

if ([UIScreen instancesRespondToSelector:@selector(scale)] && UIScreen.mainScreen.scale > 1.0) {
return true;
} else {

return false;
}
}