Cocos Creator HTML5 Game Tutorial: Build and Export Your First Web Game

Cocos Creator HTML5 Game Tutorial: Build and Export Your First Web Game

Honesty note: I chose Phaser for my game (decision explained in the engine deep-dive), but I evaluated Cocos Creator closely for its web-first export and mini-game ecosystem (the comparison). This tutorial is written from Cocos’s official docs and public 2026 community practice — accurate as a roadmap, not as my own shipped project.

TL;DR

  1. Cocos Creator is a visual, node-component editor built for web delivery — you drag nodes into a scene, attach components (including TypeScript scripts), and hit Build → Web. First export is a folder you can deploy anywhere (or import straight into portals/mini-game platforms).
  2. Learn four editor panels and you can build: Scene (the visual canvas), Hierarchy (node tree), Inspector (component properties on the selected node), Assets (your files). Everything else is convenience.
  3. The mental model: Scene = tree of Nodes; behavior = Components. A script component is a TypeScript class with lifecycle hooks (onLoad, update(dt)) — attach it to a node and it runs. That’s 90% of Cocos.
  4. TypeScript is first-class — Cocos scripts are .ts by default, with decorators (@ccclass, @property) that expose fields in the Inspector. If you want to learn one language for both Cocos and web, TS is it (my notes on adding TS to a Phaser stack).

The four panels that matter

PanelWhat it isWhat you do there
SceneThe visual canvasDrag/position/scale nodes; see the game
HierarchyThe node treeCreate/rename/parent nodes; the structure of the scene
InspectorProperties of the selected nodeSet components, edit @property fields, tweak values
AssetsYour filesImport art/audio, create scripts, manage prefabs

Open the editor, and those four are your cockpit. A beginner tutorial that teaches these four first is teaching the right 20%.

The node-component model in practice

A Cocos scene is a tree of Nodes; a node is a container with a transform (position/rotation/scale). Behavior comes from Components attached to nodes:

// Your first script component — attach to a node and it runs
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PlayerMove')
export class PlayerMove extends Component {
  @property speed: number = 200;   // shows up in the Inspector, editable live

  update(dt: number) {
    // dt = seconds since last frame; move the node every frame
    this.node.setPosition(
      this.node.position.x + this.speed * dt,
      this.node.position.y
    );
  }
}

That script attached to a node is a working moving sprite — the “hello world” of Cocos. The @property decorator is the bridge: declare a field, it appears in the Inspector, and you tune values without code.

From scene to playable: the 10-step path

  1. Create a project — Cocos Dashboard → New Project → Empty (2D) template.
  2. Build the scene — create a Canvas node (UI root), add a Sprite node under it.
  3. Import art — drag a PNG into the Assets panel; drag it onto the Sprite to set the image.
  4. Add behavior — create a .ts script (right-click Assets → Create → TypeScript), write a component, drag the script onto the node.
  5. Wire input — the input module (input.on(Input.EventType.TOUCH_START, ...)) or the Button component’s click event.
  6. Tune in Inspector — set @property values while the game preview runs (live editing).
  7. Preview — the built-in preview runs the game in browser instantly.
  8. Build → Web — Project → Build: choose Web Mobile (for browsers/portals) or Web Desktop; Cocos outputs a deployable folder.
  9. Deploy — upload that folder to any static host (Cloudflare Pages, etc.) or package for a portal; for mini-games, choose the WeChat/ByteDance build target instead (portal publishing).
  10. Optimize — check the built size, keep textures compressed, and watch draw calls (the 60fps budget).

The honest part: what to watch for

Pitfalls

  1. Clicking through panels without the model — understand node-component first; everything else follows.
  2. Giant textures imported as-is — art goes in at PNG size; compress to what the game actually displays (asset pipeline applies to any engine).
  3. No prefab discipline — reuse scenes/systems as prefabs; hand-duplicating nodes is how scenes rot.
  4. Skipping TypeScript — fighting the editor to avoid code is a losing battle as complexity grows.
  5. Ignoring export size — measure the gzipped web build before portal submission (why).

Bottom line

Cocos Creator’s path to a first web game is genuinely short: four editor panels, the node-component model, one TypeScript component, and Build → Web. The visual editor removes boilerplate; TypeScript gives it real structure as you grow; the mini-game export story is its strongest differentiator. It’s a legitimate alternative to Phaser for web-first developers who want a visual editor (the honest engine comparison) — and this tutorial gives you the 20% of Cocos that does 80% of the work.