Convert Figma logo to code with AI

cocos logococos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.

6,838
1,776
6,838
633

Top Related Projects

88,735

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

43,513

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

9,523

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

Quick Overview

The Cocos Engine is a free and open-source game engine developed by Cocos Technology. It is primarily used for creating 2D games, but also supports the development of 3D games. The engine is cross-platform, allowing developers to build games for a variety of platforms, including mobile, desktop, and web.

Pros

  • Cross-Platform Compatibility: The Cocos Engine supports multiple platforms, including iOS, Android, Windows, macOS, and HTML5, making it easier to develop and deploy games across different devices.
  • Extensive Documentation and Community: The Cocos Engine has a large and active community, with extensive documentation and resources available to help developers get started and troubleshoot issues.
  • Powerful Scripting System: The engine provides a powerful scripting system, allowing developers to write game logic in languages like JavaScript, Lua, and C++.
  • Efficient Performance: The Cocos Engine is designed to be efficient, with a focus on optimizing performance for mobile devices.

Cons

  • Steep Learning Curve: The Cocos Engine has a relatively steep learning curve, especially for developers who are new to game development or the engine's specific architecture.
  • Limited 3D Support: While the engine does support 3D game development, its 3D capabilities are not as advanced as some other game engines, such as Unity or Unreal Engine.
  • Smaller Community Compared to Alternatives: While the Cocos Engine has a large and active community, it is still smaller than the communities of some other popular game engines, which may limit the availability of third-party resources and plugins.
  • Potential Vendor Lock-in: As with any game engine, using the Cocos Engine may lead to a certain degree of vendor lock-in, as transitioning to a different engine can be a significant undertaking.

Code Examples

Here are a few examples of how to use the Cocos Engine:

  1. Creating a Simple Scene:
// Create a new scene
var scene = new cc.Scene();

// Create a new sprite
var sprite = new cc.Sprite("path/to/your/image.png");

// Set the position of the sprite
sprite.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);

// Add the sprite to the scene
scene.addChild(sprite);

// Run the scene
cc.director.runScene(scene);
  1. Handling User Input:
// Create a new scene
var scene = new cc.Scene();

// Create a new sprite
var sprite = new cc.Sprite("path/to/your/image.png");

// Set the position of the sprite
sprite.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);

// Add an event listener for touch events
sprite.on(cc.Node.EventType.TOUCH_END, function(event) {
    // Handle the touch event
    console.log("Sprite was touched!");
}, this);

// Add the sprite to the scene
scene.addChild(sprite);

// Run the scene
cc.director.runScene(scene);
  1. Animating a Sprite:
// Create a new scene
var scene = new cc.Scene();

// Create a new sprite
var sprite = new cc.Sprite("path/to/your/image.png");

// Set the position of the sprite
sprite.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);

// Create an animation from a sprite sheet
var animation = new cc.Animation();
for (var i = 1; i <= 8; i++) {
    var frameName = "frame" + i + ".png";
    animation.addSpriteFrame(cc.spriteFrameCache.getSpriteFrame(frameName));
}
animation.setDelayPerUnit(0.1);

// Create an animate action and run it
var animate = new cc.Animate(animation);
sprite.runAction(cc.repeatForever(animate));

// Add the sprite to the scene
scene.addChild(sprite);

// Run the scene
cc.director.runScene(scene);

Getting Started

To get started with the Cocos Engine, follow these steps:

  1. **Install the

Competitor Comparisons

88,735

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

Pros of Godot

  • Godot is open-source and free to use, while Cocos-engine has a commercial license for certain features.
  • Godot has a more modern and intuitive user interface, making it easier for beginners to get started.
  • Godot's scripting language, GDScript, is similar to Python, which is a popular and widely-used programming language.

Cons of Godot

  • Godot has a smaller community and ecosystem compared to Cocos-engine, which may mean fewer resources and third-party tools available.
  • Godot's performance may not be as optimized as Cocos-engine, especially for large-scale projects.
  • Godot's 3D capabilities are not as advanced as Cocos-engine's, which may be a drawback for developers working on 3D games.

Code Comparison

Cocos-engine (C++):

class Sprite : public Node {
public:
    static Sprite* create(const std::string& filename);
    bool initWithFile(const std::string& filename);
    void setPosition(const Vec2& position);
    void setScale(float scale);
};

Godot (GDScript):

extends Sprite

func _ready():
    texture = load("res://path/to/sprite.png")
    position = Vector2(100, 100)
    scale = Vector2(2, 2)
43,513

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

Pros of PixiJS

  • Lightweight and Fast: PixiJS is a lightweight and fast 2D rendering library, making it a great choice for building high-performance web applications.
  • Extensive Ecosystem: PixiJS has a large and active community, with a wide range of plugins and extensions available to extend its functionality.
  • Flexible and Customizable: PixiJS provides a flexible and customizable API, allowing developers to tailor the library to their specific needs.

Cons of PixiJS

  • Limited 3D Support: PixiJS is primarily focused on 2D rendering, and its 3D support is limited compared to other game engines like Cocos.
  • Steeper Learning Curve: PixiJS has a steeper learning curve compared to some other game engines, as it requires a deeper understanding of low-level rendering concepts.

Code Comparison

PixiJS:

const app = new PIXI.Application({ width: 800, height: 600 });
document.body.appendChild(app.view);

const sprite = PIXI.Sprite.from('assets/image.png');
sprite.x = 400;
sprite.y = 300;
sprite.anchor.set(0.5);
app.stage.addChild(sprite);

app.ticker.add((delta) => {
  sprite.rotation += 0.01 * delta;
});

Cocos:

const { ccclass, property } = cc._decorator;

@ccclass
export default class MyComponent extends cc.Component {
  @property(cc.Sprite)
  sprite: cc.Sprite = null;

  start() {
    this.sprite.node.x = 400;
    this.sprite.node.y = 300;
    this.sprite.node.anchorX = 0.5;
    this.sprite.node.anchorY = 0.5;
  }

  update(dt) {
    this.sprite.node.rotation += 0.01 * dt;
  }
}
9,523

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF

Pros of PlayCanvas Engine

  • Visual Editor: PlayCanvas Engine provides a robust visual editor that allows developers to build and design their games directly in the browser, making it more accessible for non-technical users.
  • Collaboration: PlayCanvas Engine offers built-in collaboration features, enabling multiple developers to work on the same project simultaneously, which can improve productivity and teamwork.
  • Asset Management: PlayCanvas Engine's asset management system is well-organized, allowing developers to easily manage and organize their game assets, including 3D models, textures, and scripts.

Cons of PlayCanvas Engine

  • Limited Customization: Compared to Cocos Engine, PlayCanvas Engine may have a more limited set of customization options, which could be a drawback for developers who require a high degree of control over their game engine.
  • Performance Concerns: Some users have reported performance issues with larger or more complex projects in PlayCanvas Engine, which could be a concern for developers working on demanding games.
  • Vendor Lock-in: By using PlayCanvas Engine, developers may be more reliant on the platform and its ecosystem, which could lead to a degree of vendor lock-in.

Code Comparison

Here's a brief code comparison between Cocos Engine and PlayCanvas Engine for a simple scene setup:

Cocos Engine:

// Create a scene
const scene = new cc.Scene();

// Create a sprite node
const sprite = new cc.Sprite('sprite.png');
sprite.setPosition(cc.v2(400, 300));
scene.addChild(sprite);

// Add the scene to the game
cc.director.runScene(scene);

PlayCanvas Engine:

// Create a new entity
const entity = new pc.Entity();

// Add a sprite component to the entity
entity.addComponent('sprite', {
    asset: 'sprite.png',
    pivot: [0.5, 0.5],
    position: [400, 300, 0]
});

// Add the entity to the scene
app.root.addChild(entity);

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

Pros of Babylon.js

  • Extensive Documentation and Community: Babylon.js has a comprehensive documentation and a large, active community, making it easier for developers to get started and find support.
  • Cross-Platform Compatibility: Babylon.js is designed to work across a wide range of platforms, including web browsers, mobile devices, and virtual reality (VR) headsets.
  • Performance Optimization: Babylon.js is optimized for performance, with features like WebGL 2 support and a powerful rendering engine.

Cons of Babylon.js

  • Steeper Learning Curve: Babylon.js has a more complex API and a steeper learning curve compared to Cocos Engine, which may be a barrier for some developers.
  • Limited 2D Support: While Babylon.js is primarily focused on 3D graphics, its 2D support is not as robust as Cocos Engine's.
  • Larger File Size: Babylon.js has a larger file size compared to Cocos Engine, which can impact load times and performance, especially on mobile devices.

Code Comparison

Cocos Engine:

// Create a scene
var scene = new cc.Scene();

// Create a sprite
var sprite = new cc.Sprite('example.png');
sprite.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);
scene.addChild(sprite);

// Run the scene
cc.director.runScene(scene);

Babylon.js:

// Create a scene
var scene = new BABYLON.Scene(engine);

// Create a camera
var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 2, BABYLON.Vector3.Zero(), scene);
camera.attachControl(canvas, true);

// Create a box
var box = BABYLON.MeshBuilder.CreateBox("box", {size: 1}, scene);
box.position.y = 1;

// Render the scene
engine.runRenderLoop(function () {
    scene.render();
});

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

Cocos Creator Logo

stars forks license twitter

Engine for Cocos Creator

Cocos Creator is the new generation of game development tool in Cocos family, it brings a complete set of 3D and 2D features while providing an intuitive, low cost and collaboration friendly workflow to game developers. Cocos Engine is the runtime framework for Cocos Creator editor.

image

Cocos Creator inherited many good qualities and cool features from its previous versions, such as high performance low level C++ implementation, intuitive editor, cross-platform support. It supports native platforms, web platforms and rapidly expanding instant gaming platforms, including Windows, Mac, iOS, Android, HarmonyOS, Web, Facebook Instant Games, WeChat Mini Game and TikTok Mini Games.

Furthermore, Cocos Creator has pushed the engine technology to a whole new level for high performance with scalability on various platforms, full extensibility and easy development.

  1. Modern Graphics: The GFX implementation is designed to adapt to the modern graphics APIs, it uses Vulkan on Windows and Android, Metal on Mac OS and iOS, WebGL on Web platform.
  2. High Performance: The runtime engine is built with half C++ and half TypeScript, low level infrastructure, native platform adaptation, renderer and scene management are all written in C++ to ensure high runtime performance. We continue to move heavy lifting work to native as much as possible.
  3. Customizable Render Pipeline: The render pipeline is designed to be fully customizable, it has supported the builtin forward and deferred render pipeline across all platforms. Developers can customize their own render pipeline following the same approach.
  4. Extensible Surface Shader: The material system is built on Cocos effect format which uses GLSL 300, the shader programs will be converted to suitable runtime format automatically. The surface shader permit to fully customize the surface material while ensuring universal lighting model.
  5. Physically Based Rendering (PBR): The standard effect adopts physically based rendering, along with the physically based camera and the lighting based on physical metrics, developers can easily achieve realistic and seamless rendering results across different environment.
  6. Easy TypeScript API: The user level API set is provided in TypeScript, along with the powerful VSCode editor, development with Cocos Creator is incredibly efficient.

Besides all these highlights, Cocos Creator also provides builtin animation system, physics system, particle system, terrain editing support, complex UI system, instant preview etc.

image

This open source repository is the runtime engine of Cocos Creator, the engine is naturally integrated within Cocos Creator, designed to only be the essential runtime library and not to be used independently.

Development and Contribution Notice

Cocos Creator engine is open source and welcomes community participation, for open source engine development with Cocos Creator editor, you should fork this repository and setup custom engine in the editor.

Prerequisite

Clone

Clone this repository into your local environment.

Install

In the cloned engine folder, run the following command to setup development environment:

# download & build engine dependencies
npm install

This is all you have to do to setup engine development environment.

Build

  • If running inside Cocos Creator, the engine will automatically compile and build after the editor window is opened. For more instructions on modifying the engine in Cocos Creator, please refer to Engine Customization Workflow.
  • Outside the editor, you need to run the following command to build:
npm run build

Please refer to native readme if you want to develop native applications.

Contribution

You can contribute to the Cocos Creator open source engine in many ways, they are very much appreciated:

  1. Report bug or feature requests by creating an issue.
  2. Participate discussions in the issues.
  3. Create a pull request if you have fixed or improved anything, implemented any features.
  4. Improve the documentations with pull request to the usage documentation repository.
  5. Help other developers in our Forum.

Contribution notice

If you are trying to make a pull request, there are some requirements that must be met so that your pull request can be accepted:

  1. Follow our Cpp Coding Style Guide and TypeScript Coding Style Reference.
  2. Try to integrate ESLint and CPP auto fix tools in your coding environment.
  3. Link related issues or discussions in your pull request and clearly state the purpose of your pull request.
  4. Pass all automatic continuous integration tests.
  5. Request file owner or engine developers to review your pull request.
  6. Get one valid approval from the engine architects.

Example Project

  • Mind Your Step 3D: Beginner's step-by-step tutorial project repo.
  • Test Cases: Unit test scenes for every engine module.
  • Example Cases: Simple yet expressive demo scenes for baseline testing and topic-specific case study.
  • Awesome Cocos: You can find out other useful tools and show cases here.

Links