为 Sofala 制作浏览器游戏
Players start your game right on play.sofala.market, with nothing to install: free games at once, paid ones after one payment. The easy way is to let an AI agent build and upload it; doing it by hand comes after.
和你的 AI 智能体一起
You do not need to know how to program. A coding agent writes the game with you, uploads it to Sofala, writes the listing and publishes it when you say it’s done. Any agent that works with MCP servers can do this; these steps use Claude Code on Windows, and we recommend it with the model Opus 5.5 or newer.
- Get a Claude accountGo to claude.ai, create an account and choose a paid plan (Pro or higher). Claude Code is not part of the free plan.
- Open PowerShellPowerShell is a window where you type commands. Press the Windows key, type
powershelland press Enter. A window opens with a line that starts withPS C:\Users\and your name. That is where the next lines go. - Install Claude CodeCopy this line, paste it into PowerShell (right-click pastes) and press Enter. Nothing seems to happen while it downloads; wait until it says it is done.
irm https://claude.ai/install.ps1 | iex
Now close PowerShell and open it again. This matters: the window you installed from does not know the new program yet. - Check that it worksIn the new PowerShell window, this prints a version number:
claude --version
Does it say thatclaudeis not recognized? Then Windows has not been told where Claude Code is. Paste these two lines, one after the other, close PowerShell, open it again and try once more:$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User') [Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')Still stuck? Claude Code’s page for installation problems lists the other causes. - Add Sofala, before you start Claude CodeThis tells Claude Code where Sofala is, so it can upload and publish for you. Paste it and press Enter:
claude mcp add --transport http Sofala https://sofala.market/mcp
- Start Claude CodeType this and press Enter:
claude
The first time, your browser opens and asks you to sign in with your Claude account. Do that and come back to the PowerShell window.
Does it stop to ask permission too often? Start it with this line instead, with no checks at all. It then does everything without asking, also when it gets something wrong, so use it only if you accept that; Anthropic advises it only on a computer with nothing on it that you would miss.claude --dangerously-skip-permissions
- Connect it to your Sofala accountInside Claude Code, type the line below and press Enter, pick Sofala and choose to sign in. Your browser opens sofala.market: type your email address, then the code Sofala emails you. That also makes your Sofala account if you have none; it is free and has no password. Then press Allow. Back in Claude Code, Sofala now shows as connected.
/mcp
- Pick the modelType the line below, press Enter and choose Opus 5.5 or newer. A game is a lot of code, and smaller models make more mistakes.
/model
- Ask for your gameNow say what you want, in your own words and in any language. For example:
Make a simple online multiplayer snake game that runs in the browser, for Sofala. Use Sofala’s multiplayer rooms so friends can join. Let me test it, and when I say it’s done, put it on Sofala as a free game.
- When the game is ready to try, your agent gives you a link to play it on Sofala before anyone else can see it. Say what to change, as often as you like: “make the snakes faster”, “add a score board”.
- Happy with it? Say “publish it”. A person at Sofala plays each new game before it goes up; you get an email when it is live.
- To change a live game later, open PowerShell, start Claude Code again and ask. The new build replaces the old one at the same address.
- On a Mac or on Linux, open Terminal instead of PowerShell and install with the line on Claude Code’s setup page; the other steps are the same. Using another agent? Add a remote MCP server with the address
https://sofala.market/mcp.
For manual game devs
Building or packaging the game yourself? This is what Sofala expects. An AI agent follows the same rules; it reads them from Sofala.
ZIP
- index.html 用来启动游戏。把它放在 ZIP 的最顶层,或 ZIP 唯一的文件夹里。
- 游戏加载的所有内容都在 ZIP 里,用相对路径链接:Build/game.wasm,绝不用 /Build/game.wasm,也不用你自己网站的完整地址。
- 压缩后最多 1 GB,10 000 个文件,解压后最多 2 GB。
引擎和文件类型
- 任何能在浏览器里运行的游戏都可以:HTML5 canvas、WebGL 和 WebGPU(three.js、Babylon.js、PixiJS、Phaser、PlayCanvas)、WebAssembly(Emscripten、Rust、Bevy、Go)、Godot 3 和 4、GameMaker、Construct、Defold、PICO-8、RPG Maker,以及通过 love.js 的 LÖVE。
- Unity WebGL:任何压缩方式都可以。Brotli 和 gzip 文件会带着正确的头发送,所以不需要 decompression fallback。
- JavaScript 模块、import map、.mjs 文件、glTF 和 GLB 模型、KTX2 纹理以及 WAV、OGG、Opus 和 MP3 声音,都会以正确的类型发送。
多线程游戏
- 使用线程(SharedArrayBuffer)的版本,例如开启线程的 Godot 4、带 -pthread 的 Emscripten,以及多线程的 Unity 或 love.js 版本,需要跨源隔离的页面。上传 ZIP 时 Sofala 会识别出来并以这种方式运行。只用 Brotli 压缩的 Unity 版本,请在商品里勾选“需要 SharedArrayBuffer”。
- 隔离运行的游戏无法从其他网站加载脚本、图片或声音,除非对方发送 CORS 或 Cross-Origin-Resource-Policy 头,所以请把所有内容放进 ZIP。不使用线程的游戏可以从其他网站加载。
游戏内部
- 保存在 localStorage 或 IndexedDB 里的进度留在玩家的浏览器里,每款游戏分开保存。
- 游戏可以使用全屏、鼠标指针、手柄、声音和 WebXR。Sofala 的页面上也有全屏按钮。
- 游戏在自己的地址上、在沙盒框架里运行:不能打开弹窗、离开页面,也看不到玩家的 Sofala 账户。不要让玩家在游戏里登录或付款;游戏由 Sofala 销售。
- 多人游戏不需要你自己的服务器:Sofala 运行房间(见下文)。游戏也可以与你自己的服务器通信。
手机和平板
- 请在游戏的某个元素上监听触摸,例如它的 canvas,而不是 window 或 document:在框架内,iPhone 不一定会把触摸传给 window。
- 给这个元素设置 CSS touch-action: none,并在它的 touchstart 和 touchmove 监听器中调用 preventDefault(),这些监听器要用 { passive: false } 添加。否则手机会把滑动当作页面滚动,几个像素之后就不再通知你的游戏。
- 手机上也会收到 pointer 事件(pointerdown、pointermove)。游戏可以同时监听两种,只要一根手指只算一次。
- Snake Party 做到了这一切,它的滑动在 iPhone 上也能用;它的源代码展示了做法。
- 如果你的游戏是用引擎做的,触摸输入由引擎负责。不管用什么做的,发布前都请在手机上试一试。
const area = document.querySelector('canvas'); // an element of the game, not window
area.style.touchAction = 'none';
let from = null;
area.addEventListener('touchstart', e => {
e.preventDefault();
from = [e.touches[0].clientX, e.touches[0].clientY];
}, { passive: false });
area.addEventListener('touchmove', e => {
e.preventDefault();
if (!from) return;
const x = e.touches[0].clientX, y = e.touches[0].clientY, dx = x - from[0], dy = y - from[1];
if (Math.abs(dx) < 20 && Math.abs(dy) < 20) return;
from = [x, y];
swipe(Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? 'right' : 'left') : (dy > 0 ? 'down' : 'up'));
}, { passive: false });多人游戏
- Sofala 运行房间,所以你的游戏不需要服务器。把 sofala-game-1.1.js 放进 ZIP,和 index.html 放在一起,在你自己的脚本之前加载,一行代码就能让玩家和其他人进入同一个房间。
- 一名玩家发送的内容会按发送顺序到达房间里的其他人。一个房间最多 32 名玩家,每人每秒可发送 60 条消息,每条最多 16 KB:适合回合制、派对和轻松的实时游戏。快节奏的射击游戏仍然需要自己的服务器。
- Sofala 不运行你的任何代码。在房间里待得最久的玩家是房主:让房主运行游戏,并把变化告诉其他人。房主离开后,下一位玩家成为房主。
- 快速游戏会填充公开房间。私人房间有一个代码,朋友可以用它加入。
- 游戏通过一个在你的游戏中始终不变的 id 和玩家名来识别每位玩家,绝不会用邮箱地址或账号。玩家名就是他在 Sofala 上的名字,除非他在账号页面选了别的名字;你的游戏也可以让玩家在加入时输入名字。未登录就玩免费游戏的人是访客。
- 在你自己的电脑上也一样:从 localhost 打开游戏,房间就是你专属的测试空间。
- 如果你确实运行了服务器,Sofala.token() 会给它一个签名的 token,说明玩家是谁。请用
https://sofala.market/game-api/keys上的公钥验证。
<script src="sofala-game-1.1.js"></script>
<script type="module">
const room = await Sofala.rooms.quick({ max: 4 }); // a room with other players, or a new one
room.on('message', (data, from) => { /* from.name did something */ });
room.on('enter', peer => { });
room.on('exit', peer => { });
room.send({ move: 'e2e4' }); // to everyone else in the room
</script>房间能做的一切都列在 sofala-game-1.1.js 的开头。一个可以照着学的完整游戏,只有一个文件:Snake Party(它的源代码)。
销售
- 可以免费,也可以定一个含增值税的价格,最低 €0.50。你通过 Stripe 收到不含增值税的价格,扣除 Sofala 的 5% 佣金和 Stripe 的手续费:请先在“销售”页面设置收款。
- 商品的第一张封面照片就是游戏在 play.sofala.market 上的图块;宽幅 16:9 的截图效果最好。可在商品编辑页添加更多截图和预览视频。
- 每款新游戏上线前,Sofala 都会有人亲自试玩;上线后你会收到邮件。
- 要更新已上线的游戏,请上传新的 ZIP(智能体:带 replace 的 upload_files)。大约一分钟后就会替换旧版本,无需重新审核,地址不变,玩家的存档也会保留。