Convert Figma logo to code with AI

cocos2d logococos2d-html5

Cocos2d for Web Browsers. Built using JavaScript.

3,058
905
3,058
251

Top Related Projects

43,513

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

5,851

a fresh, modern & lightweight HTML5 game engine

36,911

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.

1,403

Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.

3,409

JavaScript Game Engine

2D HTML5 rendering and layout engine for game development

Quick Overview

Cocos2d-html5 is an open-source game framework for creating HTML5 games and applications. It is a port of the popular Cocos2d-x engine, designed specifically for web browsers, allowing developers to create cross-platform games using JavaScript and HTML5 technologies.

Pros

  • Cross-platform compatibility, allowing games to run on various web browsers and devices
  • Rich set of features including sprite manipulation, animations, particle systems, and physics engines
  • Active community and extensive documentation
  • Seamless integration with other web technologies and libraries

Cons

  • Performance may not be as optimal as native game engines for complex games
  • Limited 3D capabilities compared to more advanced game engines
  • Learning curve can be steep for developers new to game development
  • Dependency on browser technologies may lead to inconsistencies across different platforms

Code Examples

  1. Creating a simple sprite:
var sprite = new cc.Sprite("path/to/image.png");
sprite.setPosition(cc.p(100, 100));
this.addChild(sprite);
  1. Adding a simple action to a sprite:
var moveAction = cc.moveTo(2, cc.p(200, 200));
sprite.runAction(moveAction);
  1. Creating a simple scene:
var HelloWorldLayer = cc.Layer.extend({
    ctor: function() {
        this._super();
        var size = cc.winSize;
        
        var label = new cc.LabelTTF("Hello World", "Arial", 40);
        label.setPosition(size.width / 2, size.height / 2);
        this.addChild(label, 1);
        
        return true;
    }
});

var HelloWorldScene = cc.Scene.extend({
    onEnter: function() {
        this._super();
        var layer = new HelloWorldLayer();
        this.addChild(layer);
    }
});

Getting Started

  1. Download and include the Cocos2d-html5 library in your project.
  2. Create an HTML file with a canvas element:
<!DOCTYPE html>
<html>
<head>
    <title>My Cocos2d Game</title>
</head>
<body>
    <canvas id="gameCanvas" width="800" height="450"></canvas>
    <script src="path/to/cocos2d-js-v3.js"></script>
    <script src="src/game.js"></script>
</body>
</html>
  1. Initialize the game in your JavaScript file (game.js):
cc.game.onStart = function(){
    cc.view.adjustViewPort(true);
    cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.SHOW_ALL);
    cc.view.resizeWithBrowserSize(true);
    cc.LoaderScene.preload(g_resources, function () {
        cc.director.runScene(new HelloWorldScene());
    }, this);
};
cc.game.run();

Competitor Comparisons

43,513

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

Pros of PixiJS

  • Better performance for complex 2D graphics and animations
  • More active development and community support
  • Flexible and lightweight, allowing easier integration with other libraries

Cons of PixiJS

  • Steeper learning curve for beginners
  • Less comprehensive documentation compared to Cocos2d-html5
  • Fewer built-in game-specific features

Code Comparison

PixiJS:

const app = new PIXI.Application();
document.body.appendChild(app.view);
const sprite = PIXI.Sprite.from('image.png');
app.stage.addChild(sprite);
app.ticker.add(() => sprite.rotation += 0.01);

Cocos2d-html5:

var HelloWorldLayer = cc.Layer.extend({
    ctor: function() {
        this._super();
        var sprite = new cc.Sprite("image.png");
        this.addChild(sprite);
        this.schedule(function() {
            sprite.rotation += 0.01;
        });
        return true;
    }
});

PixiJS focuses on rendering performance and flexibility, making it suitable for complex 2D graphics applications. It has a more modern API and active development. Cocos2d-html5 provides a more structured game development framework with built-in features, making it easier for beginners to create games quickly. However, it has less flexibility and performance optimization compared to PixiJS.

5,851

a fresh, modern & lightweight HTML5 game engine

Pros of melonJS

  • Lightweight and focused on 2D game development
  • Built-in physics engine (based on Box2D)
  • Active community and regular updates

Cons of melonJS

  • Less comprehensive documentation compared to Cocos2d-html5
  • Smaller ecosystem and fewer third-party extensions
  • Steeper learning curve for beginners

Code Comparison

melonJS:

me.game.onload = function() {
    me.state.set(me.state.PLAY, new PlayScreen());
    me.state.change(me.state.PLAY);
};

Cocos2d-html5:

cc.game.onStart = function(){
    cc.director.runScene(new MyScene());
};
cc.game.run();

Both frameworks use similar concepts for game initialization and scene management, but with different syntax and structure. melonJS uses a state-based approach, while Cocos2d-html5 employs a more direct scene management system.

melonJS is generally more suitable for developers focusing on 2D game development with built-in physics, while Cocos2d-html5 offers a broader range of features and better documentation, making it more accessible for beginners and larger projects.

36,911

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.

Pros of Phaser

  • More active development and larger community support
  • Better documentation and extensive examples
  • Built-in physics engines (Arcade Physics and Matter.js)

Cons of Phaser

  • Steeper learning curve for beginners
  • Larger file size, which may impact load times for web games

Code Comparison

Phaser (creating a simple sprite):

function create() {
    this.add.sprite(400, 300, 'player');
}

Cocos2d-html5 (creating a simple sprite):

var sprite = new cc.Sprite("player.png");
sprite.setPosition(400, 300);
this.addChild(sprite);

Both frameworks allow for easy sprite creation and positioning, but Phaser's syntax is slightly more concise. Phaser uses a scene-based structure, while Cocos2d-html5 follows a more traditional object-oriented approach.

Phaser is generally considered more modern and feature-rich, with better performance for complex games. However, Cocos2d-html5 may be easier for developers familiar with other Cocos2d variants or those looking for a simpler framework for basic 2D games.

The choice between the two depends on project requirements, team expertise, and desired features. Phaser is often preferred for web-based game development due to its active community and extensive plugin ecosystem.

1,403

Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.

Pros of Kiwi.js

  • More modern and actively maintained
  • Better documentation and community support
  • Easier to integrate with modern web development workflows

Cons of Kiwi.js

  • Smaller ecosystem and fewer plugins compared to Cocos2d-html5
  • Less optimized for mobile devices
  • Steeper learning curve for beginners

Code Comparison

Kiwi.js:

var game = new Kiwi.Game('content', 'MyGame', state, { renderer: Kiwi.RENDERER_WEBGL });
var state = new Kiwi.State('MyState');
state.create = function() {
    this.sprite = new Kiwi.GameObjects.Sprite(this, this.textures.sprite, 100, 100);
    this.addChild(this.sprite);
};

Cocos2d-html5:

var MyScene = cc.Scene.extend({
    onEnter: function () {
        this._super();
        var layer = new cc.LayerColor(cc.color(255, 255, 255, 255));
        var sprite = new cc.Sprite("res/sprite.png");
        sprite.setPosition(100, 100);
        layer.addChild(sprite);
        this.addChild(layer);
    }
});

Both frameworks offer similar functionality for creating game scenes and adding sprites, but Kiwi.js uses a more modern JavaScript syntax and structure. Cocos2d-html5 follows a more traditional object-oriented approach with class extension.

3,409

JavaScript Game Engine

Pros of Crafty

  • Lightweight and modular architecture, allowing for easier customization
  • Strong community support with active development and frequent updates
  • Built-in entity-component system for flexible game object management

Cons of Crafty

  • Less comprehensive documentation compared to Cocos2d-html5
  • Smaller ecosystem of plugins and extensions
  • Steeper learning curve for developers new to entity-component systems

Code Comparison

Crafty:

Crafty.e('2D, DOM, Color')
  .attr({x: 0, y: 0, w: 100, h: 100})
  .color('red');

Cocos2d-html5:

var sprite = new cc.Sprite();
sprite.setPosition(0, 0);
sprite.setContentSize(100, 100);
sprite.setColor(cc.color(255, 0, 0));
this.addChild(sprite);

Both frameworks offer ways to create and manipulate game objects, but Crafty's entity-component system allows for more concise and flexible code. Cocos2d-html5 follows a more traditional object-oriented approach, which may be more familiar to some developers but can lead to more verbose code.

2D HTML5 rendering and layout engine for game development

Pros of stage.js

  • Lightweight and minimalistic, focusing on performance and efficiency
  • Easy to learn and use, with a simple API and clear documentation
  • Supports both Canvas and WebGL rendering, providing flexibility

Cons of stage.js

  • Less feature-rich compared to cocos2d-html5, which offers more built-in functionality
  • Smaller community and ecosystem, potentially leading to fewer resources and extensions
  • Limited support for complex game development scenarios

Code Comparison

stage.js:

Stage(function(stage) {
  var box = Stage.image('box').pin('align', 0.5);
  stage.root.append(box);
});

cocos2d-html5:

var MyScene = cc.Scene.extend({
  onEnter: function () {
    this._super();
    var sprite = new cc.Sprite("box.png");
    sprite.setPosition(cc.winSize.width / 2, cc.winSize.height / 2);
    this.addChild(sprite);
  }
});

The code comparison shows that stage.js has a more concise syntax for creating and positioning elements, while cocos2d-html5 follows a more object-oriented approach with scene management and inheritance.

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-html5

Cocos2d-html5 is a cross-platform 2D game engine written in JavaScript, based on Cocos2d-X and licensed under MIT. It incorporates the same high level api as “Cocos2d JS-binding engine” and compatible with Cocos2d-X. It currently supports canvas and WebGL renderer.


Cocos2d-html5 has evolved to Cocos Creator, 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. 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 latest repository is maintained in here Engine of Cocos Creator.


Cross Platform

  • Popular browsers: Chrome 14+, Safari 5.0+, IE9+, Firefox 3.5+.
  • Mobile platforms: Mobile browsers,Facebook Instant Games and Mini Games.
  • Native App: Same piece of code can run on "Cocos2d JS-Binding Engine" without or with little modification.

Documentation

Contact us