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

How to make a Successful Mobile Game

A Successful Mobile Game should have the following characteristics

  • Very simple Story line
  • The game has to be easy to learn and understand (People do not spend much time to learn mobile games)
  • Models and textures which have an unique look, but still follow consistent themes
  • Little input, Big output (Simple but huge amount of feedback)
  • Physics based game play (Physics give much variations on same input)
  • A bright, fun, cartoon y and cute visual style
  • Well-chosen color palettes which support the mood of the game
  • Lightning which is used to set and enhance the mood of each scenario
  • Player should be constantly rewarded
  • Hide an unexpectedness feature
  • Scenarios which look diverse, but still fit together
  • Motivate users to play with stick and carrot policy
  • Huge amount of levels but very short to play

Scripting Engine at Cocos2d-iphone Game Engine

Each Game Engine is different and solves different problems in different ways, so the engine design does vary greatly from engine to engine (even though a lot of principles are shared from engine to engine).

Having a scripting engine is a big plus. This solves the problem of critical functions (file access, leader boards, authentication process…) being exposed to the scripting interface.

  • Cocos2d-iphone (Since Version 2.1) integrates JavaScript bindings.

Resources:

https://github.com/cocos2d/cocos2d-iphone/wiki/cocos2d-and-JavaScript

https://github.com/vlidholt/CocosDragonJS

http://www.learn-cocos2d.com/2012/05/learn-create-cocos2d-game-lua-scripting-physics-tilemaps-arc/

  • Kobold2D which is based on Cocos2D comes with Lua bindings.

Resources:

http://www.learn-cocos2d.com/2011/08/comparison-lua-scripting-corona-sdk-wax-kobold2d/

http://www.kobold2d.com/pages/viewpage.action?pageId=917888