1. Home
  2. /
  3. Cocos2dx Typing Test
  4. /
  5. Cocos2d-x Simple Counter Game

Cocos2d-x Simple Counter Game - Cocos2dx Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Cocos2d-x Simple Counter Game — Cocos2dx Code

A basic Cocos2d-x example that creates a counter label and buttons to increment or decrement the value.

#include "CounterScene.h"
#include "ui/CocosGUI.h"

USING_NS_CC;

Scene* CounterScene::createScene() {
	auto scene = Scene::create();
	auto layer = CounterScene::create();
	scene->addChild(layer);
	return scene;
}

bool CounterScene::init() {
	if (!Layer::init()) return false;

	count = 0;
	label = Label::createWithTTF("Count: 0", "fonts/Marker Felt.ttf", 24);
	label->setPosition(Vec2(200, 200));
	this->addChild(label);

	auto incButton = ui::Button::create();
	incButton->setTitleText("+");
	incButton->setPosition(Vec2(150, 100));
	incButton->addClickEventListener([&](Ref*) { updateCount(1); });
	this->addChild(incButton);

	auto decButton = ui::Button::create();
	decButton->setTitleText("-");
	decButton->setPosition(Vec2(250, 100));
	decButton->addClickEventListener([&](Ref*) { updateCount(-1); });
	this->addChild(decButton);

	return true;
}

void CounterScene::updateCount(int delta) {
	count += delta;
	label->setString("Count: " + std::to_string(count));
}

Cocos2dx Language Guide

Cocos2d-x is a cross-platform, open-source C++ game engine optimized for 2D games, offering high performance, a lightweight architecture, scene graph system, physics, animations, particle effects, and deployment to mobile, desktop, web, and consoles.

Primary Use Cases

  • ▸2D mobile games
  • ▸Casual/hypercasual games
  • ▸Educational games/apps
  • ▸Lightweight 2D engines for indie developers
  • ▸Cross-platform 2D desktop or mobile publishing

Notable Features

  • ▸High-performance C++ core
  • ▸Scene graph architecture
  • ▸Sprites + Actions + Transitions
  • ▸Box2D & Chipmunk physics
  • ▸Cross-platform deployment

Origin & Creator

Cocos2d-x originated from the Python-based Cocos2d project, created by Ricardo Quesada. It was later rewritten in C++ by Chukong Technologies and released in 2010 as a fast cross-platform engine for mobile.

Industrial Note

Cocos2d-x dominates the mobile 2D gaming industry in Asia, powering thousands of games in China, Japan, and Korea - especially hypercasual games, casino games, match-3 titles, and educational products requiring fast rendering.

Quick Explain

  • ▸Cocos2d-x uses C++ as its core programming language with optional JavaScript/Lua bindings.
  • ▸It provides a scene graph, sprite system, actions, transitions, physics, UI widgets, audio, and efficient rendering pipelines.
  • ▸Cocos2d-x powers countless 2D mobile games, educational apps, casual titles, animation apps, and high-performance 2D experiences on Android, iOS, and desktop.

Core Features

  • ▸Scene management
  • ▸Sprite system
  • ▸Actions (move, rotate, scale, fade)
  • ▸Particle system
  • ▸UI widgets via Cocos UI

Learning Path

  • ▸Learn C++ basics
  • ▸Understand nodes/scenes/actions
  • ▸Add physics and UI
  • ▸Build for Android/iOS
  • ▸Optimize and publish

Practical Examples

  • ▸Endless runner
  • ▸Match-3 puzzle game
  • ▸Physics-based slingshot game
  • ▸Casino/slots game
  • ▸2D platformer with tilemap

Comparisons

  • ▸Cocos2d-x vs Unity: lightweight 2D vs full 3D engine
  • ▸Cocos2d-x vs Godot: C++ performance vs editor-driven workflow
  • ▸Cocos2d-x vs Cocos Creator: C++ native vs JS editor-based
  • ▸Cocos2d-x vs LibGDX: C++ vs Java approach
  • ▸Cocos2d-x vs Phaser: mobile native vs browser-first

Strengths

  • ▸Extremely lightweight and fast
  • ▸Native performance with C++
  • ▸Huge mobile game track record
  • ▸Cross-platform with small runtime footprint
  • ▸Ideal for 2D animations and sprite-heavy games

Limitations

  • ▸Not suited for 3D or complex console games
  • ▸Steep C++ learning curve for beginners
  • ▸UI editor ecosystem is weaker than Unity
  • ▸Fewer modern engine tools
  • ▸Maintenance requires manual project configuration

When NOT to Use

  • ▸3D-heavy games
  • ▸AAA production games
  • ▸Complex UI-based apps
  • ▸Beginner-friendly visual editing
  • ▸Projects needing rapid prototyping

Cheat Sheet

  • ▸Scene = top container
  • ▸Layer = logic/UI section
  • ▸Node = base element
  • ▸Action = animation tool
  • ▸Director = main controller

FAQ

  • ▸Is Cocos2d-x free?
  • ▸Yes - MIT licensed.
  • ▸Does it support Android/iOS?
  • ▸Yes - highly optimized for both.
  • ▸Is Cocos2d-x still maintained?
  • ▸Yes - especially in mobile markets.
  • ▸Is it good for 3D?
  • ▸No - mostly 2D with limited 3D.
  • ▸Is it beginner friendly?
  • ▸Somewhat - requires C++ knowledge.

30-Day Skill Plan

  • ▸Week 1: Nodes, scenes, actions
  • ▸Week 2: Physics + collisions
  • ▸Week 3: UI + audio systems
  • ▸Week 4: Export Android/iOS builds
  • ▸Week 5: Monetization + analytics

Final Summary

  • ▸Cocos2d-x is a lightweight, high-performance C++ engine ideal for 2D mobile games.
  • ▸Uses scene graph, sprites, physics, and actions to build rich 2D gameplay.
  • ▸Highly popular in Asia's mobile gaming industry.
  • ▸Cross-platform and open-source with tiny runtime footprint.
  • ▸Best for developers wanting full control, performance, and native execution.

Project Structure

  • ▸Classes/ - C++ source files
  • ▸Resources/ - images, audio, fonts
  • ▸proj.android - Android config
  • ▸proj.ios_mac - iOS/macOS config
  • ▸CMakeLists.txt - build configuration

Monetization

  • ▸AdMob integration
  • ▸In-app purchases
  • ▸Subscription systems
  • ▸Rewarded video ads
  • ▸Casino monetization models

Productivity Tips

  • ▸Use spritesheets always
  • ▸Prefer Actions over manual updates
  • ▸Use debug draw for collision tuning
  • ▸Keep draw calls minimal
  • ▸Use CMake presets

Basic Concepts

  • ▸Director: manages game loop
  • ▸Scene: main container
  • ▸Layer: UI/logic layer
  • ▸Node: base class for visual objects
  • ▸Action: animations applied to nodes

Official Docs

  • ▸https://docs.cocos.com
  • ▸https://cocos2d-x.org
  • ▸https://github.com/cocos2d/cocos2d-x

More Cocos2dx Typing Exercises

Cocos2d-x Basic Hello World SceneCocos2d-x Touch Move SpriteCocos2d-x Sprite Movement with ActionsCocos2d-x Keyboard Input MovementCocos2d-x UI Button ExampleCocos2d-x Particle Effect ExampleCocos2d-x Background MusicCocos2d-x Sprite Animation ExampleCocos2d-x Scene Transition Fade

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher