Convert Figma logo to code with AI

cocos2d logococos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.

18,196
7,055
18,196
1,606

Top Related Projects

90,206

Godot Engine – Multi-platform 2D and 3D game engine

23,262

Desktop/Android/HTML5/iOS Java game development framework

22,183

A simple and easy-to-use library to enjoy videogames programming

10,120

Simple and Fast Multimedia Library

7,412

🐍🎮 pygame (the library) is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

4,988

LÖVE is an awesome 2D game framework for Lua.

Quick Overview

Cocos2d-x is a popular open-source game development framework for building 2D and 3D games across multiple platforms. It provides a comprehensive set of tools and libraries for creating high-performance games using C++, with additional bindings for Lua and JavaScript.

Pros

  • Cross-platform compatibility (iOS, Android, Windows, macOS, Linux)
  • Extensive feature set for 2D and 3D game development
  • Active community and regular updates
  • Good performance and optimization capabilities

Cons

  • Steeper learning curve compared to some other game engines
  • Documentation can be inconsistent or outdated in some areas
  • Limited visual editor capabilities compared to Unity or Unreal Engine
  • Smaller ecosystem of third-party tools and plugins

Code Examples

  1. Creating a simple sprite:
auto sprite = Sprite::create("player.png");
sprite->setPosition(Vec2(100, 100));
this->addChild(sprite);
  1. Adding a touch event listener:
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event* event) {
    // Handle touch event
    return true;
};
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
  1. Creating a simple animation:
Vector<SpriteFrame*> frames;
for (int i = 1; i <= 5; i++) {
    frames.pushBack(SpriteFrame::create(StringUtils::format("animation%d.png", i), Rect(0, 0, 100, 100)));
}
auto animation = Animation::createWithSpriteFrames(frames, 0.1f);
auto animate = Animate::create(animation);
sprite->runAction(RepeatForever::create(animate));

Getting Started

  1. Download and install Cocos2d-x from the official website.
  2. Set up your development environment (Visual Studio for Windows, Xcode for macOS).
  3. Create a new project using the command line tool:
cocos new MyGame -p com.example.mygame -l cpp -d ./projects
  1. Open the project in your IDE and start developing your game.
  2. Build and run your game on your desired platform using the provided build scripts or IDE integration.

Competitor Comparisons

90,206

Godot Engine – Multi-platform 2D and 3D game engine

Pros of Godot

  • Fully open-source and free to use, with a more permissive MIT license
  • Integrated development environment (IDE) with visual editor
  • Supports multiple programming languages (GDScript, C#, C++)

Cons of Godot

  • Smaller community and ecosystem compared to Cocos2d-x
  • Less optimized for mobile platforms, especially for complex 3D games

Code Comparison

Godot (GDScript):

extends Sprite

func _ready():
    position = Vector2(100, 100)
    scale = Vector2(2, 2)

Cocos2d-x (C++):

auto sprite = Sprite::create("image.png");
sprite->setPosition(Vec2(100, 100));
sprite->setScale(2.0f);
this->addChild(sprite);

Both engines offer simple ways to create and manipulate sprites, but Godot's GDScript provides a more concise syntax. Cocos2d-x uses C++, which may be more familiar to some developers and potentially offers better performance. Godot's scene-based structure allows for more modular development, while Cocos2d-x follows a more traditional object-oriented approach.

23,262

Desktop/Android/HTML5/iOS Java game development framework

Pros of libGDX

  • Cross-platform development with a single codebase (Java)
  • Extensive documentation and active community support
  • Flexible and modular architecture, allowing for easy customization

Cons of libGDX

  • Steeper learning curve for developers new to Java
  • Less optimized for mobile platforms compared to Cocos2d-x
  • Limited built-in UI tools and editors

Code Comparison

libGDX:

public class MyGame extends ApplicationAdapter {
    @Override
    public void create() {
        // Game initialization code
    }
}

Cocos2d-x:

class MyScene : public cocos2d::Scene {
public:
    static cocos2d::Scene* createScene();
    virtual bool init();
};

Summary

libGDX offers cross-platform development with Java, extensive documentation, and a flexible architecture. However, it has a steeper learning curve and less optimization for mobile platforms compared to Cocos2d-x. libGDX uses Java for game development, while Cocos2d-x primarily uses C++. Both frameworks have their strengths, and the choice between them depends on the developer's preferences and project requirements.

22,183

A simple and easy-to-use library to enjoy videogames programming

Pros of raylib

  • Lightweight and easy to learn, with a simple API
  • Cross-platform support for desktop, web, and mobile
  • No external dependencies, making it easier to set up and deploy

Cons of raylib

  • Less comprehensive feature set compared to Cocos2d-x
  • Smaller community and ecosystem
  • Limited support for advanced 2D game development features

Code Comparison

raylib:

#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "raylib [core] example - basic window");
    while (!WindowShouldClose())
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Cocos2d-x:

#include "cocos2d.h"

class HelloWorld : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();
    virtual bool init();
    CREATE_FUNC(HelloWorld);
};

bool HelloWorld::init()
{
    if (!Scene::init()) return false;
    auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
    label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height));
    this->addChild(label, 1);
    return true;
}
10,120

Simple and Fast Multimedia Library

Pros of SFML

  • Simpler and more lightweight, making it easier to learn and use
  • More flexible and customizable, allowing for greater control over low-level operations
  • Better suited for 2D game development and multimedia applications

Cons of SFML

  • Less comprehensive feature set compared to Cocos2d-x
  • Smaller community and ecosystem, resulting in fewer resources and third-party tools
  • Limited support for mobile platforms and cross-platform development

Code Comparison

SFML example:

#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);
    
    while (window.isOpen()) {
        // Event handling and drawing logic
    }
    return 0;
}

Cocos2d-x example:

#include "cocos2d.h"

class MyScene : public cocos2d::Scene {
public:
    CREATE_FUNC(MyScene);
    bool init() override {
        if (!Scene::init()) return false;
        auto sprite = cocos2d::Sprite::create("sprite.png");
        this->addChild(sprite);
        return true;
    }
};
7,412

🐍🎮 pygame (the library) is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

Pros of Pygame

  • Simpler learning curve, especially for Python beginners
  • Extensive documentation and community support
  • Lightweight and easy to set up

Cons of Pygame

  • Limited built-in features compared to Cocos2d-x
  • Performance may be slower for complex games
  • Less suitable for cross-platform mobile development

Code Comparison

Pygame example:

import pygame

pygame.init()
screen = pygame.display.set_mode((800, 600))
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

Cocos2d-x example:

#include "cocos2d.h"

class MyScene : public cocos2d::Scene {
public:
    static cocos2d::Scene* createScene();
    virtual bool init();
    CREATE_FUNC(MyScene);
};

Pygame is more straightforward for simple 2D games, while Cocos2d-x offers a more comprehensive framework for complex, cross-platform game development. Pygame is Python-based, making it accessible for beginners, whereas Cocos2d-x uses C++, providing better performance but with a steeper learning curve. Cocos2d-x excels in mobile game development and offers more built-in features, while Pygame is better suited for quick prototyping and educational purposes.

4,988

LÖVE is an awesome 2D game framework for Lua.

Pros of LÖVE

  • Simpler and more beginner-friendly
  • Lightweight and faster to set up
  • Cross-platform with a single codebase

Cons of LÖVE

  • Less feature-rich compared to Cocos2d-x
  • Limited to 2D game development
  • Smaller community and ecosystem

Code Comparison

LÖVE (main.lua):

function love.draw()
    love.graphics.print("Hello World!", 400, 300)
end

Cocos2d-x (HelloWorldScene.cpp):

bool HelloWorld::init() {
    if (!Scene::init()) return false;
    auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
    label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height));
    this->addChild(label, 1);
    return true;
}

LÖVE uses Lua, which is more concise and easier to read, especially for beginners. Cocos2d-x uses C++, offering more control but with increased complexity. LÖVE's simplicity allows for quicker prototyping, while Cocos2d-x provides more advanced features and better performance for larger projects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

cocos2d-x

Win32Others
Build statusBuild Status

cocos2d-x is a multi-platform framework for building 2d games, interactive books, demos and other graphical applications. It is based on cocos2d-iphone, but instead of using Objective-C, it uses C++. It works on iOS, Android, macOS, Windows and Linux.

Cocos2d-x Framework Architecture:

cocos2d-x is:

  • Fast
  • Free
  • Easy to use
  • Community supported

Git user attention

  1. Clone the repo from GitHub.

      $ git clone https://github.com/cocos2d/cocos2d-x.git
    
  2. After cloning the repo, please execute download-deps.py to download and install dependencies.

      $ cd cocos2d-x
      cocos2d-x $ python download-deps.py
    
  3. After running download-deps.py.

      cocos2d-x $ git submodule update --init
    

Download stable versions

Documentations and samples

Main features

  • Scene management (workflow)
  • Transitions between scenes
  • Sprites and Sprite Sheets
  • Effects: Lens, Ripple, Waves, Liquid, etc.
  • Actions (behaviours):
    • Transformation Actions: Move, Rotate, Scale, Fade, Tint, etc.
    • Composable actions: Sequence, Spawn, Repeat, Reverse
    • Ease Actions: Exp, Sin, Cubic, Elastic, etc.
    • Misc actions: CallFunc, OrbitCamera, Follow, Tween
  • Basic menus and buttons
  • Integrated with physics engines: Box2d and Chipmunk
  • Particle system
  • Skeleton Animations: Spine and Armature support
  • Fonts:
    • Fast font rendering using Fixed and Variable width fonts
    • Support for .ttf fonts
  • Tile Map support: Orthogonal, Isometric and Hexagonal
  • Parallax scrolling
  • Motion Streak
  • Render To Texture
  • Touch/Accelerometer on mobile devices
  • Touch/Mouse/Keyboard on desktop
  • Sound Engine support
  • Integrated Slow motion/Fast forward
  • Fast and compressed textures: PVR compressed and uncompressed textures, ETC1 compressed textures, and more
  • Resolution Independent
  • Language: C++, with Lua and JavaScript bindings
  • Open Source Commercial Friendly(MIT): Compatible with open and closed source projects
  • OpenGL ES 2.0 (mobile) / OpenGL 2.1 (desktop) / metal(macos and iOS) based

Build Requirements

  • Mac OS X 10.7+, Xcode 8+
  • or Ubuntu 14.04+, CMake 3.1+
  • or Windows 7+, VS 2015
  • Python 2.7.5+(NOT Python 3)
  • NDK r16+ is required to build Android games
  • Android Studio 3.0.0+ to build Android games(tested with 3.0.0)
  • JRE or JDK 1.6+ is required for web publishing

Runtime Requirements

  • iOS 8.0+ for iPhone / iPad games
  • Android 3.0.0+ for Android
  • OS X v10.9+ for Mac games
  • Windows 7+ for Win games

Environment Setup

Should set up environment before starting a new game or running tests

$ cd cocos2d-x
$ ./setup.py
$ source FILE_TO_SAVE_SYSTEM_VARIABLE

Should invoke this script if using linux system

$ cd cocos2d-x
$ ./install-linux-deps.sh

Running Tests

$ cd cocos2d-x
$ mkdir build
$ cd build
$ cocos run --proj-dir .. -p [mac|win32|android|linux|ios]

How to start a new game

$ cd cocos2d-x
$ ./setup.py
$ source FILE_TO_SAVE_SYSTEM_VARIABLE
$ cocos new MyGame -p com.your_company.mygame -l cpp -d NEW_PROJECTS_DIR
$ cd NEW_PROJECTS_DIR/MyGame
$ mkdir build
$ cd build
$ cocos run --proj-dir .. -p [mac|win32|android|linux|ios]

You can also create a Lua project with -l lua.

Using IDE

If need to debug program, then it is more convinent to use IDE to run and debug it. All platforms other than Android can use CMake to generate corresponding project file. Can refer to Detail CMake Guide for detail information.

For Android, the Android Studio project file lies in PROJECT_DIR/proj.android. Can just use Android Studio to import the exsting project file.

Learning Resources

Spreading the word!

You can help us spread the word about cocos2d-x! We would surely appreciate it!

Where to get help

Contributing to the Project

Cocos2d-x is licensed under the MIT License. We welcome participation!

Did you find a bug? Do you have feature request? Do you want to merge a feature?

Embrace the Future: Switch to Cocos Creator for a Better Experience

Cocos Creator is the new generation of Cocos game engine with a full featured editor and content creation friendly workflow. It supports all major platforms allowing games to be quickly released for the web, iOS, Android, Windows, Mac, and various mini-game platforms. Millions of developers have built 2D / 3D experiences, from hardcore games to web instant entertainment. A pure JavaScript-developed engine runtime is available on the web and mini-game platforms for better performance and smaller packages. On other native platforms, C++ is used to implement the underlying framework, providing greater operational efficiency. The engine is completely open source, and retains the advantages of Cocos2d-x which includes high performance, customizability, ease for debugging, easy to learn, and small package size.

Therefore, we no longer recommend new users to start with Cocos2d-x. Instead, please use the brand-new Cocos Creator for project development to enjoy the best editor and 3D support.