Introduction
Cocos2d-x is the C++ rewrite of the original Cocos2D (Python/Objective-C). Over a decade of commercial game development has hardened it into a reliable mobile engine — it ships the client for Clash Royale, Pokémon Quest, Geometry Dash, Hearthstone (variants), and thousands more, especially in the Asian mobile market.
With over 19,000 GitHub stars (plus a separate cocos-engine repo for the newer TypeScript-based Cocos Creator 3.x), Cocos remains a dominant choice for studios that want cross-platform C++ performance with a mature 2D feature set.
What Cocos2d-x Does
Cocos2d-x provides the classic scene-graph game engine primitives: Director (runs the main loop), Scene (container), Layer (groups), Sprite (graphics), Action (tweens + animations), EventDispatcher (input + custom events). Resource management, physics (Box2D or Chipmunk), audio, particle systems, and font rendering are all built in. The newer Cocos Creator 3.x replaces this with a Unity-like TypeScript editor.
Architecture Overview
[Cocos2d-x (C++ core)]
|
[Director] — main loop driver
|
[Scene graph]
Node -> Layer -> Sprite / Label / ParticleSystem / TileMap
|
[Subsystems]
Renderer (OpenGL ES 2/3, Metal)
Audio (SimpleAudioEngine, AudioEngine)
Physics (Box2D, Chipmunk)
Event (touch, keyboard, accelerometer)
Networking (HTTP, WebSocket, SocketIO)
|
[Platform layer]
iOS (Objective-C++), Android (JNI), Windows, macOS, Linux, HarmonyOS
|
[Scripting (optional)]
Lua (cocos2d-x bindings)
JavaScript (ScriptCore / V8 bindings)Self-Hosting & Configuration
// AppDelegate.cpp — application entry
bool AppDelegate::applicationDidFinishLaunching() {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview) {
glview = GLViewImpl::createWithRect("MyGame", Rect(0, 0, 960, 640));
director->setOpenGLView(glview);
}
director->getOpenGLView()->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);
director->setAnimationInterval(1.0f / 60.0f);
director->runWithScene(HelloWorldScene::create());
return true;
}
// HelloWorldScene.cpp — a scene with sprite + input
bool HelloWorld::init() {
if (!Scene::init()) return false;
auto sprite = Sprite::create("HelloWorld.png");
sprite->setPosition(Vec2(480, 320));
addChild(sprite);
auto move = MoveBy::create(2.0f, Vec2(100, 0));
auto back = move->reverse();
sprite->runAction(RepeatForever::create(Sequence::create(move, back, nullptr)));
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [sprite](Touch* t, Event*) {
sprite->setPosition(t->getLocation());
return true;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}# Cross-platform build
cocos compile -p ios --mode release
cocos compile -p android --mode release
cocos compile -p win32 --mode release
cocos compile -p mac --mode releaseKey Features
- Scene graph — classic Node tree, Sprite/Layer/Scene primitives
- Action system — tweens, sequences, repeats, eases composable declaratively
- Physics — Box2D + Chipmunk built in
- Multiplatform — iOS, Android, Windows, macOS, Linux, HarmonyOS
- Scripting — Lua + JavaScript bindings for iteration speed
- Audio — AudioEngine with polyphony, 3D audio, effects
- Particle system — fire, smoke, magic built in
- Mature tooling — profiler, memory tracker, asset tools
Comparison with Similar Tools
| Feature | Cocos2d-x | Unity | Godot | Defold | Phaser |
|---|---|---|---|---|---|
| Language | C++ (+ Lua/JS) | C# | GDScript / C# | Lua | JS/TS |
| Mobile focus | Yes (primary) | Yes | Yes | Yes (primary) | Web + mobile |
| Editor | No (code-first) + Cocos Creator | Yes | Yes | Yes | No |
| Royalties | No | Yes (above $ threshold) | No | No | No |
| Maturity | Very mature | Very mature | Mature | Mature | Mature |
| Best For | Commercial mobile games | All-purpose | Indie + 2D/3D | Lua-scripted mobile | Web games |
FAQ
Q: Cocos2d-x vs Cocos Creator? A: Cocos2d-x is a C++ library. Cocos Creator 3.x is a Unity-like editor with TypeScript scripting that uses the same engine core. For editor-driven workflow, use Creator; for pure code + C++ customization, use cocos2d-x.
Q: Is it still relevant in 2026? A: For shipping mobile games at scale, yes — it's battle-tested with patches + security updates. For new projects, also consider Godot / Unity / Unreal / Bevy depending on needs.
Q: Can I ship to consoles? A: Through 3rd-party ports and commercial licensing, yes (Nintendo Switch ports exist). Not officially supported out of the box.
Q: Performance vs Unity? A: Cocos has lower overhead for pure 2D — cheaper draw calls, smaller binary. Unity is more versatile but ships with more runtime baggage. For cheap-device mobile markets, Cocos wins binary size + RAM.
Sources
- GitHub: https://github.com/cocos2d/cocos2d-x
- Newer: https://github.com/cocos/cocos-engine
- Website: https://www.cocos.com
- License: MIT