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;


Unit Testing at Cocos2d-x Game Engine

Several Unit Testing framework for CPP based projects

  • CxxTest
  • Boost Test
  • UnitTest++
  • googletest
  • MsTest
  • NUnit

Cocos2d-x, a multi platform 2d Game Engine, to work with, I chose UnitTest++

Because UnitTest++ is

  • A C++ unit-testing framework designed with game development in mind.
  • Lightweight.
  • Easy to integrate, minimal work required to create a new test.
  • Covers major unit testing features
  • No dependency at monolithic project folder structure
  • Minimal footprint and minimal reliance on heavy libraries.
  • Good assert and crash handling.
  • No dynamic memory allocations done by the framework, which makes it much easier to track memory leaks and generally more attractive for embedded systems.

The driving forces behind the design of UnitTest++ are:

  • Portability. As game developers, we need to write tests for a variety of platforms, most of which are not supported by normal software packages (all the game consoles). So the ability to easily port the framework to a new platform was very important.
  • Simplicity. The simpler the framework, the easier it is to add new features or adapt it to meet new needs, especially in very limited platforms.
  • Development speed. Writing and running tests should be as fast and straightforward as possible. We’re going to be running many tests hundreds of times per day, so running the tests should be fast and the results well integrated with the workflow.


Download UnitTest++ Framework from here.