cocos2d
Use when the user asks about Cocos Creator 3.x, Cocos2d-x, a Cocos game, node and component scripting in TypeScript, Cocos builds for web or mobile, or Cocos…
от j4flmao★ 47 звёзд на GitHub
Установить cocos2d в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Cocos2d-x / Cocos Creator Deep Engineering Guide
Purpose
Cocos2d is a family of open-source game frameworks for 2D (and now 3D in Creator) with strong mobile focus. Cocos2d-x is the C++ core; Cocos Creator is the full editor + scene system built on top. This guide focuses on Cocos Creator 3.x (which uses Cocos2d-x under the hood).
Agent Protocol
Trigger
"cocos2d", "cocos2d-x", "cocos creator", "cocos game", "cocos build".
Input Context
- Cocos Creator or Cocos2d-x version
- Target platforms (web, iOS, Android, mini-games)
- Game type and performance targets
Output Artifact
TypeScript/C++ code, project settings or a performance plan. No file unless requested.
Response Format
Engine: {Cocos Creator 3.x | Cocos2d-x}
Change: {what and why}
Code: {snippet}
Perf check: {draw calls, memory, FPS on target device}
1. Engine Architecture
Cocos Creator 3.x
Application
Scene -> Node tree
Component (Script, Render, Audio, UI, Physics...)
Scheduler (main loop): tick() -> update() -> lateUpdate()
Director: scene management, frame pacing
- Director is the central controller;
director.mainLoop()runs the frame. - Nodes are the tree; Components (scripts) attach behavior.
- Scheduler: manages
update(),lateUpdate(),physicsUpdate()with priorities.
1.1 Update Order
update(dt) // component gameplay logic per frame
physics step // PhysicsSystem.instance.fixedTimeStep (default 1/60), may run 0..maxSubSteps times
lateUpdate(dt) // camera follow, UI
render // pipeline submit
Rules:
- Drive dynamic bodies through the physics API (
RigidBody.setLinearVelocity(),applyForce()), not by writing node positions every frame. - Components have no
fixedUpdate; for fixed-step logic listen to the physics system's step events or run your own accumulator inupdate.
2. The Node-Component Model
import { Component, Collider, ICollisionEvent, _decorator } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('Player')
export class Player extends Component {
@property speed: number = 10;
update(deltaTime: number) {
// movement, animation, input
}
start() {
// 3D: collider events are registered, not overridden
this.getComponent(Collider)!.on('onCollisionEnter', this.onHit, this);
// 2D equivalent: collider2d.on(Contact2DType.BEGIN_CONTACT, cb, this)
}
private onHit(event: ICollisionEvent) {
// event.otherCollider, event.contacts
}
}
2.1 Pattern: Event-Driven
// Emit
this.node.emit('damage', amount);
// Listen
this.node.on('damage', this.onDamage, this);
node.on(): listen on the same node or bubble up.targetOff(): remove all listeners on cleanup.- Use typed events where possible (Cocos Creator 3.x supports
EventTarget).
2.2 Prefab Instantiation
import { director, instantiate, Prefab } from 'cc';
const bullet = instantiate(this.bulletPrefab);
director.getScene()!.addChild(bullet);
bullet.setWorldPosition(this.node.worldPosition);
Rule: cache prefab references via @property(Prefab), never load per frame.
3. Rendering
3.1 Pipeline Backends
| Platform | Renderer |
|---|---|
| Android / desktop GL | OpenGL ES 3 |
| iOS / Metal devices | Metal |
| Android Vulkan | Vulkan (via Cocos 3.x) |
| Web | WebGL 2 (WebGL 1 fallback); WebGPU experimental in 3.8 |
3.2 Draw Calls & Batching
- 2D renderables sharing material + texture are batched automatically; dynamic atlas merging can pack small textures at runtime. Interleaving different textures/materials in sibling order breaks batches.
- Use texture atlases (
TexturePacker) aggressively. - UI:
MaskandGraphicscomponents break batches; keep them few. Check the draw-call count in the Profiler overlay (profiler.showStats()).
3.3 Custom Rendering (Cocos Creator 3.x)
// Per-object uniform change without affecting the shared material
const renderer = this.getComponent(MeshRenderer)!;
renderer.getMaterialInstance(0)!.setProperty('mainColor', new Color(255, 0, 0, 255));
Material instances break batching/instancing for that object; prefer instanced attributes for many objects.
RenderPipeline(Forward, Deferred) set in Project Settings.- 2D games use Forward renderer; 3D can opt Deferred.
4. Physics
- Cocos Creator 3.x lets you pick the backend in Project Settings > Feature Cropping: 3D = Bullet (wasm, default), PhysX, cannon.js or builtin (collision only); 2D = Box2D or builtin.
- Nodes:
Collider2D/Collider3D+RigidBody2D/RigidBody3D. - Contact callbacks:
onBeginContact,onEndContact. - Layers:
physicsGroupin Project Settings.
4.1 Character Controller
const controller = this.node.getComponent(CharacterController);
controller.move(dir, deltaTime);
- For platformers:
RigidBody2D+BoxCollider2D, manual
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл cocos2d?
Use when the user asks about Cocos Creator 3.x, Cocos2d-x, a Cocos game, node and component scripting in TypeScript, Cocos builds for web or mobile, or Cocos performance. Produces Cocos project structure, gameplay code and build settings. Not for Cocos2d-x engine internals (use cocos2d-patterns) or other engines (use unity or godot).
Как установить скилл cocos2d?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cocos2d запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…