Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
用点点看模板做一个单人小游戏并在浏览器中试玩
games/hello
hello/ ├── manifest.json 包的清单 ├── index.html ├── style.css ├── main.js └── pack.sh 打包成 .nlgame
{ "schema": 1, "id": "hello", "name": "点点看", "version": "0.1.0", "build": 1, "entry": "index.html", "orientation": "portrait", "background": "#10202a", "sdk": ">=1.0 <2", "scopes": ["game.identity", "game.energy.read", "game.haptics", "game.share"], "network": { "connect": [], "img": [] }, "players": { "min": 1, "max": 1 } }
id
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, user-scalable=no"> <link rel="stylesheet" href="style.css"> <script src="nl-game-sdk.js"></script> <script src="main.js" defer></script> </head> <body> <header><img id="avatar" alt=""><b id="name">…</b><small id="energy"></small></header> <main><button id="target" type="button">开始</button><p id="score"></p></main> <footer> <button id="share" type="button" hidden>叫朋友来玩</button> <p id="signin" hidden><button id="login" type="button">登录</button>后显示你的名字和游戏能量</p> </footer> </body> </html>
async function boot() { nl.setLoadingProgress(0.5); try { // 右上角是宿主的「退出」胶囊,标题栏要避开它 const cap = await nl.ui.getCapsuleRect(); // {x, y, width, height} if (cap.width > 0) document.querySelector("header").style.paddingRight = `${innerWidth - cap.x + 8}px`; } catch {} await nl.ready(); // 关闭宿主加载页,越早越好 loadUser(); } async function loadUser() { try { const me = await nl.auth.getUser(); $("name").textContent = me.name || me.username; if (me.avatar) $("avatar").src = me.avatar; } catch (e) { if (e.code === "AUTH_REQUIRED") { $("signin").hidden = false; return; } // 没登录不是网络错误 } try { const w = await nl.energy.getWallet(); $("energy").textContent = `游戏能量 ${w.balance}`; } catch {} // 权限没批时 SCOPE_DENIED } // 登录必须在点击事件里调用 $("login").addEventListener("click", () => nl.auth.login().then(loadUser, () => {})); $("target").addEventListener("click", () => { /* 计数 */ nl.haptics.impact("light"); }); $("share").addEventListener("click", () => nl.share.invite({ title: "点点看", text: "来点点看" })); nl.lifecycle.on("pause", () => { /* 切到后台时作废这一局 */ }); boot();
pack.sh
games/hello/pack.sh 2 # 生成 games/hello/dist/hello-0.1.0-2.nlgame
https://www.nodeloc.com/games/hello
manifest.json
name
orientation
scopes
此页面对您有帮助吗?