<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: PHT</title>
    <description>The latest articles on DEV Community by PHT (@pht1991).</description>
    <link>https://dev.to/pht1991</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4172930%2F3196c55c-2972-4519-a19a-f9070c48883d.jpg</url>
      <title>DEV Community: PHT</title>
      <link>https://dev.to/pht1991</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pht1991"/>
    <language>en</language>
    <item>
      <title>Cocos Creator 3.8 for Beginners: Build Your First Mini-Game</title>
      <dc:creator>PHT</dc:creator>
      <pubDate>Fri, 09 Oct 2026 09:37:23 +0000</pubDate>
      <link>https://dev.to/pht1991/cocos-creator-38-for-beginners-build-your-first-mini-game-5bdn</link>
      <guid>https://dev.to/pht1991/cocos-creator-38-for-beginners-build-your-first-mini-game-5bdn</guid>
      <description>&lt;h2&gt;
  
  
  description: "A hands-on walkthrough to your first Cocos Creator 3.8 WeChat mini-game — project setup, the node + component model, your first TypeScript script, and the build-to-DevTools flow, with the gotchas I hit shipping a real game."
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Cross-post note:&lt;/strong&gt; This is the original article from my blog, &lt;a href="https://phtbyte.com/articles/cocos-creator-beginner-guide.html" rel="noopener noreferrer"&gt;Indie Game Lab&lt;/a&gt;. Read it there for the properly styled version, or keep reading here — it's identical.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; You don't need a game-design degree to ship something on Cocos Creator 3.8 — you need the &lt;em&gt;flow&lt;/em&gt;: create a WeChat mini-game project, understand that everything is a &lt;strong&gt;node with components&lt;/strong&gt;, write one tiny TypeScript script, then build and preview in WeChat DevTools. I shipped a full survival/crafting game on this exact pipeline (the post-mortem is &lt;a href="https://phtbyte.com/articles/how-i-built-kubi.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;), and the beginner path below is the same five steps I wish someone had handed me on day one — plus the three gotchas that cost me real hours.&lt;/p&gt;

&lt;p&gt;This guide assumes zero Cocos experience. If you're still deciding whether Cocos is even the right engine, my &lt;a href="https://phtbyte.com/articles/cocos-vs-unity-vs-godot.html" rel="noopener noreferrer"&gt;engine comparison&lt;/a&gt; makes the call for a solo indie. If you've already built a prototype, skip to the build-and-preview section — but read the gotchas even if you skip everything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What you'll have at the end
&lt;/h2&gt;

&lt;p&gt;By the end of this walkthrough you'll have a mini-game you can tap to play in WeChat DevTools: a character sprite that moves when you press a key or tap the screen, sitting in a scene you assembled yourself. It won't be the next hit — but it will be &lt;em&gt;real, running code&lt;/em&gt;, and every game I've shipped started as exactly this: one sprite that does one thing.&lt;/p&gt;

&lt;p&gt;More importantly, you'll internalize the one mental model Cocos is built around, because almost every beginner confusion (why doesn't my image show up? why won't it move? where do I put my code?) comes from not seeing it yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Step 1 — Create the project (and pick the right template)
&lt;/h2&gt;

&lt;p&gt;Open Cocos Creator 3.8 LTS and hit &lt;strong&gt;New Project&lt;/strong&gt;. Two choices matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Template:&lt;/strong&gt; pick the &lt;em&gt;2D&lt;/em&gt; template (or the "Empty" 2D one if you want zero boilerplate). Most mini-games — including mine — are 2D.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save path:&lt;/strong&gt; avoid deep paths with spaces or Chinese characters. A short ASCII path like &lt;code&gt;D:/dev/my-first-game&lt;/code&gt; saves you from cryptic build errors later.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You do &lt;em&gt;not&lt;/em&gt; need to pick "WeChat Mini Game" as a template — that's not a starting template, it's a &lt;em&gt;build target&lt;/em&gt; you choose later. Start in the editor like any other project; the WeChat part is a one-click build at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Step 2 — The node + component model (the thing to understand)
&lt;/h2&gt;

&lt;p&gt;This is the core. In Cocos, the scene is a &lt;strong&gt;tree of nodes&lt;/strong&gt;. A node is just a position in space with a transform. It does nothing by itself. To make a node &lt;em&gt;do&lt;/em&gt; something — show an image, play sound, run logic — you attach &lt;strong&gt;components&lt;/strong&gt; to it. A sprite on screen is a node that happens to carry a &lt;code&gt;Sprite&lt;/code&gt; component (which points at a texture) and a &lt;code&gt;Transform&lt;/code&gt; component (where it sits).&lt;/p&gt;

&lt;p&gt;This separation is why beginners get stuck: they add an image but forget the Sprite component, or write code but never attach the script component to a node. The rule is simple — &lt;strong&gt;code lives in components, components live on nodes, nodes live in the scene tree.&lt;/strong&gt; Nothing runs unless it's attached to a node in the tree.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F494sf8slwebbkmvkwwbo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F494sf8slwebbkmvkwwbo.png" alt="The Cocos scene-tree model: a Player node carrying Transform, Sprite, and a custom MoveScript component, with update() running ~60×/sec." width="799" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The whole engine in one picture: a node in the tree, the components that give it behavior, and the update loop that runs your script ~60 times a second.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Step 3 — Your first script (make it move)
&lt;/h2&gt;

&lt;p&gt;Right-click the &lt;code&gt;assets&lt;/code&gt; panel → &lt;strong&gt;New → TypeScript&lt;/strong&gt; → name it &lt;code&gt;MoveScript&lt;/code&gt;. Double-click to open it. Cocos gives you a stub with &lt;code&gt;start()&lt;/code&gt; and &lt;code&gt;update()&lt;/code&gt;. Edit it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;_decorator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Node&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ccclass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;property&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_decorator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;ccclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MoveScript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MoveScript&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deltaTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// move right at 100 units per second&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setPosition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;deltaTime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;position&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the crucial step beginners miss: &lt;strong&gt;attach the script to the node.&lt;/strong&gt; Drag &lt;code&gt;MoveScript.ts&lt;/code&gt; from the assets panel onto your Player node in the &lt;em&gt;Hierarchy&lt;/em&gt;, or select the node and click &lt;strong&gt;Add Component → Custom → MoveScript&lt;/strong&gt; in the &lt;em&gt;Inspector&lt;/em&gt;. Hit the play button at the top — the sprite drifts right. That's your first game logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Step 4 — Build for WeChat Mini Game
&lt;/h2&gt;

&lt;p&gt;Top menu → &lt;strong&gt;Project → Build…&lt;/strong&gt;. Set:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Platform:&lt;/strong&gt; WeChat Mini Game&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start Scene:&lt;/strong&gt; your main scene&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Appid:&lt;/strong&gt; your WeChat mini-game appid (or use the "test" appid while learning — Cocos accepts a placeholder for local preview)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two flags matter for real projects and trip up everyone eventually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Separate Engine:&lt;/strong&gt; ON. It splits the engine from your code so the engine is cached by WeChat and your updates stay tiny. I left this off once and wondered why every upload was huge.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MD5 Cache:&lt;/strong&gt; ON for production. It lets WeChat cache unchanged files so players re-download less on update.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click &lt;strong&gt;Build&lt;/strong&gt;. Cocos outputs a folder (default &lt;code&gt;build/wechatgame/&lt;/code&gt;). You don't open that folder directly — you open it &lt;em&gt;with&lt;/em&gt; DevTools, next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Step 5 — Preview in WeChat DevTools (the gotcha)
&lt;/h2&gt;

&lt;p&gt;Install &lt;strong&gt;WeChat DevTools&lt;/strong&gt; (the mini-program IDE, not the consumer WeChat app). In Cocos &lt;strong&gt;Preferences → Engine Manager&lt;/strong&gt;, point "WeChat DevTools Path" at the installed executable — Cocos uses it to auto-launch the preview.&lt;/p&gt;

&lt;p&gt;The gotcha: &lt;strong&gt;never open WeChat DevTools first and then build.&lt;/strong&gt; Build from Cocos &lt;em&gt;first&lt;/em&gt;, then let Cocos (or the "Preview" button) launch DevTools and import the folder. If DevTools is already open on a stale build, it silently shows the old version and you'll think your code didn't take. Close DevTools, build, then preview.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fisxy92sps8w9jiyj7dwu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fisxy92sps8w9jiyj7dwu.png" alt="The five-step path from an empty Cocos project to a running WeChat mini-game preview." width="800" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Five steps, in order. The only non-obvious part is step 5: build before you open DevTools, or you'll be debugging yesterday's code.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Three gotchas that cost me real hours
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The WeChat size ceiling is real.&lt;/strong&gt; A mini-game's main package is capped at 4 MB, with subpackages adding more. My first build blew past it in a weekend. The fix isn't "make fewer features" — it's engine subpackaging, an asset audit, and a device-tier split, which I wrote up in my &lt;a href="https://phtbyte.com/articles/bundle-size-optimization.html" rel="noopener noreferrer"&gt;bundle-size teardown&lt;/a&gt;. Learn the ceiling now, not at launch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Perf is a device problem, not an editor problem.&lt;/strong&gt; It runs smooth on your laptop and stutters on a three-year-old phone. Draw calls and overdraw dominate the frame on mobile — my &lt;a href="https://phtbyte.com/articles/cocos-draw-call-optimization.html" rel="noopener noreferrer"&gt;runtime perf teardown&lt;/a&gt; shows the three moves that fixed mine. Profile on a real device early.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code that isn't attached to a node doesn't exist.&lt;/strong&gt; If your script "does nothing," 9 times out of 10 it's not on a node in the scene tree, or the node isn't in the active scene. Check the Hierarchy, not the code, first.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  8. Where to go next
&lt;/h2&gt;

&lt;p&gt;You now have a sprite that moves. That's the seed of everything. From here the natural path is: add input (tap/keyboard) to control direction, add a second node as an obstacle, then a score. When you're ready to ship something bigger than a demo, the two articles that saved my real release are the &lt;a href="https://phtbyte.com/articles/bundle-size-optimization.html" rel="noopener noreferrer"&gt;bundle-size teardown&lt;/a&gt; and the &lt;a href="https://phtbyte.com/articles/cocos-draw-call-optimization.html" rel="noopener noreferrer"&gt;draw-call optimization&lt;/a&gt; piece — read them before your build crosses a few megabytes or your frame time crosses 16 ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Takeaways
&lt;/h2&gt;

&lt;p&gt;Cocos Creator 3.8 is approachable: create a 2D project, internalize that &lt;em&gt;nodes carry components and components carry your code&lt;/em&gt;, write one &lt;code&gt;update()&lt;/code&gt; loop, then build to WeChat and preview through DevTools (build first, open DevTools second). The engine hides the hard parts — package ceilings and mobile perf — until launch day, so learn those constraints early via the bundle and draw-call write-ups. Everything you ship later is just more nodes, more components, and more loops. Start small, ship the sprite that moves, then grow it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://phtbyte.com/articles/cocos-creator-beginner-guide.html" rel="noopener noreferrer"&gt;Indie Game Lab&lt;/a&gt;. If you found this useful, that's where the deeper teardowns (bundle size, draw calls, the full game post-mortem) live.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cocoscreator</category>
      <category>gamedev</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
