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
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;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s