Communitygithub.com

evalix098/tiktoklive

在此 TanStack Start + React 應用程式中,建立瀏覽器遊戲、互動式 / Canvas / 3D 體驗。適用於任何遊戲、模擬或 WebGL / Canvas 體驗(2D 或 3D、單人遊玩)。涵蓋遊戲迴圈與時間控制、3D 方向 / 攝影機慣例、碰撞、效能、素材、音訊、存檔、遊戲手感及各遊戲類型的操作手冊。

tiktoklive 是什麼?

此技能提供了一個完整的框架,用於在 TanStack Start + React 應用程式中建立可遊玩、正確的瀏覽器遊戲。它作為核心參考,專注於遊戲迴圈、時間控制、3D 方向、攝影機慣性、碰撞偵測、效能最佳化、素材處理、音訊整合和進度儲存等關鍵方面。該技能特別強調使用三.js 進行 3D 開發,並透過 `@react-three/fiber`、`drei` 和 `@react-three/rapier` 等函式庫提供 React 整合。對於 2D 遊戲,它支援原生 Canvas 2D API 和 Phaser 3 引擎。一個關鍵的設計原則是委派輸入控制(特別是 WASD、轉向和飛行控制)給專門的「controls」技能,以避免常見的反轉控制錯誤。該技能還包含多種遊戲類型(如 FPS、平台遊戲、賽車、益智遊戲)的詳細參考手冊、生成 2D 遊戲素材的工作流程(使用 `game-asset-core` 和 `generate2dsprite`),以及單人、AI 機器人或最多 8 人 P2P 多人遊戲的支援。它確保遊戲沒有主控台錯誤且可遊玩,並包含在行動裝置上使用觸控控制的正確設定。

相容平台✓Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/evalix098/tiktoklive/tree/HEAD/.grok/skills/building-games

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

建立遊戲

建立一個可遊玩且正確的瀏覽器遊戲,而非靜態畫面。遊戲只是一個帶有 <canvas>(或 R3F 的 <Canvas>)以及 DOM 覆蓋 UI 的 React 路由。使用 design-ui 技能設計覆蓋 UI(開始畫面、HUD、選單);此技能負責遊戲迴圈和遊戲世界。

控制項 / 反轉 A/D: 在撰寫 WASD、轉向或飛行輸入之前,請先開啟 .grok/skills/controls/SKILL.md。如果你只閱讀此文件或單一類型的操作手冊,車輛/飛行示範經常會出現 A/D 翻轉的問題。

範圍說明 — 單人、機器人、或小型 P2P 合作:

  • 預設提供單人或單人 + AI / 機器人。
  • 支援 2–8 人合作 / 休閒即時(共享游標、派對遊戲、朋友間的休閒動作)— 請使用 multiplayer-p2p 技能(WebRTC 網格,透過 /api/rtc 發送訊號)。請先閱讀其信任模型。
  • 目前唯一支援的多人遊戲模式是 P2P。請不要半途而廢地建立無法連線的 Socket。

參考資料(按需載入):

  • controls 技能(../controls/)— 必須用於移動/轉向/飛行:玩家可見的 A/D、反轉轉向反模式、飛行副翼、強制自我測試及 window.__controlsTest。對於車輛/飛機來說不是可選項。
  • references/threejs-foundational.md — 深入的 3D / 迴圈 / 效能參考。3D 請閱讀此文件。
  • references/3d-libs.md — three.js + @react-three/fiber + drei + rapier 使用說明。
  • threejs 技能(../threejs/)— 官方完整的 Three.js + TSL API 轉儲(llms-full.txt)。用於進階材質/著色器/WebGPU/載入器;不適用於簡單的 2D Canvas 遊戲。
  • references/babylon.md — Babylon.js,功能齊全的 3D 引擎替代方案。
  • references/phaser.md — Phaser 3,2D 遊戲的預設引擎。
  • references/ecs-architecture.md — 適用於大型遊戲的實體-元件-系統結構。
  • references/genres/*.md — 各類型的操作手冊(FPS、2D 平台遊戲、賽車卡丁車、益智三消俄羅斯方塊、體素麥塊、無盡跑酷、俯視角雙搖桿、塔防、棋盤卡牌西洋棋)。類型文件不能取代 controls。
  • references/game-feel-juice.md、input.md、audio.md、collision-physics.md、save-persistence.md、procedural-generation.md、ai-pathfinding.md。
  • game-asset-core(+ game-animation-frames / game-tilesets / game-character-consistency / game-ui-icons)— 在生成精靈、工作表、圖塊或 UI 時,提供引擎就緒的 2D 美術預設值和驗證(參見 §6)。

為你的建置選擇特定的類型/主題參考;此文件是遊戲迴圈/世界的通用核心。輸入方向 → controls。 2D 遊戲美術 → game-asset-core。


1. 遊戲迴圈與時間控制(最常見的正確性問題)

  • 使用引擎的 RAF 迴圈驅動遊戲迴圈(renderer.setAnimationLoop、R3F 的 useFrame 或 2D Canvas 的 requestAnimationFrame)。絕對不要使用 setInterval/setTimeout/Date.now() 進行遊戲時間控制。
  • 根據 delta 時間(秒)縮放所有移動/動畫,使速度與幀率無關(60Hz vs 144Hz)。每幀計算一次 delta 並重複使用它。
    • three.js:使用 THREE.Timer(不要使用 Clock — 在同一幀第二次呼叫 Clock.getDelta() 會回傳約 0,這是一個經典的凍結錯誤)。
  • 限制 delta 上限(min(delta, 0.1)),以免背景分頁中的遊戲讓物體瞬間移動。
  • 固定時間步長用於物理/遊戲性: 累積 delta 並以固定速率(例如 1/60)逐步執行模擬,同時以顯示速率渲染 — 可防止穿模和非確定性。

2. 控制項(委派給 controls 技能)

在實作任何 WASD / 轉向 / 飛行程式碼之前,請先開啟 .grok/skills/controls/SKILL.md。 該技能是以下內容的真相來源:

  • 玩家可見的 A = 左 / D = 右(追蹤攝影機,同時向前移動)
  • 為何 KeyA → steer− + yaw += steer * +rate 會反轉(最常見的錯誤)
  • 車輛與 FPS(平移 ≠ 轉向)、固定翼副翼、直升機/無人機注意事項
  • 強制自我測試及 window.__controlsTest 探測

請不要將 genres/racing-kart.md 視為轉向方向的唯一參考 — 飛機、水上摩托車和機甲永遠不會開啟它。

簡短提醒(完整細節在 controls 中):

// 車輛偏航本體(追蹤攝影機):在此基礎上,A 必須增加偏航
forward = (-sin(yaw), 0, -cos(yaw))
// KeyA → steer = +1;  yaw += steer * turnRate * speedFactor * dt
// 錯誤(反轉出廠):KeyA → steer = -1; yaw += steer * turnRate * dt
  • 指標鎖定: 僅滑鼠視角 — 自行實作 WASD;點擊即可開始的覆蓋層;鎖定時關閉。
  • 使用按鍵按住狀態 + dt 追蹤按鍵;透過 references/input.md 統一裝置。
  • 完成: 執行 controls 技能的檢查清單。對於車輛/飛行來說,僅截圖是不夠的。

3. 3D 方向與世界物件(「側向/反向」錯誤)

  • three.js 是右手座標系,+Y 向上:+X 向右,+Y 向上,+Z 朝向觀看者。網格面向 +Z;攝影機看向 −Z(經典的「攝影機反向」陷阱)。
  • 像 Cone/Cylinder 這樣的圖元預設指向 +Y → 旋轉以讓尖端對齊前方向(geo.rotateX(Math.PI/2))。
  • 將網格朝向 forward(網格面向 +Z):最簡單的正確方式是 mesh.lookAt(mesh.position.clone().add(forward))。要手動建立基向量,將 +Z 列設為 forward,並選擇能保持正確右手旋轉(det = +1)的 x 軸: xAxis = normalize(cross(up, forward)),然後 makeBasis(xAxis, up, forward)。 請注意,這是 cross(up, forward) — 並非 §2 中的移動 right = cross(forward, up)。以 +Z(而非攝影機的 −Z)為目標會翻轉 x 軸方向,使得 xAxis × up = forward;框架保持右手座標系(無鏡像)。對於網格,請不要使用 makeBasis(xAxis, up, -forward) — 這是以 −forward(攝影機慣例)為目標,因此網格會面向後方。
  • 將攝影機朝向 forward(攝影機看向 −Z):將 +Z 列設為 -forward — xAxis = normalize(cross(forward, up)),然後 makeBasis(xAxis, up, -forward)(或者直接使用 camera.lookAt(target))。
  • 保持一致的 world up,使物件保持直立;僅旋轉平面圖元使其站立。
  • 驗證 glTF 匯入方向;使用 AxesHelper/ArrowHelper 除錯。直立自我測試:角色站立在地平面上,而非躺著或陷入地面。

4. 攝影機必須與移動方向一致

  • 保留專用的 moveForward/moveRight 用於移動,僅計算一次,且絕不被攝影機程式碼修改(共用一個暫存向量會導致攝影機和移動不一致 — 這是一個真實的可重現錯誤)。
  • 第三人稱跟隨:desired = playerPos + up*height + moveForward*(-followDist);使用 lerp 將攝影機移向目標位置(使用基於指數的平滑,按 delta 縮放),lookAt(player)。
  • 隔離圖層的除錯順序:(1)按鍵註冊 →(2)移動方向正確 →(3)攝影機一致。請依此順序修正。

5. 效能

  • 最小化繪製呼叫(renderer.info.render.calls,目標 <100):共用材質,對重複物件使用 InstancedMesh/BatchedMesh,使用圖集。
  • 自行釋放 GPU 資源(geometry/material/texture.dispose())在關卡切換時 — three.js 不會對它們進行垃圾回收。使用物件池管理子彈/敵人/粒子。
  • 避免每幀分配(重複使用暫存向量)。壓縮紋理;對遠處使用 LOD。

6. 素材(避免生成照片的陷阱)

  • 互動式 3D 元素(武器視角模型、角色、道具、投射物)→ 從 3D 幾何 / glTF 建立,而非生成的圖片。將一個平面的照片寫實 JPG 槍枝握持圖用作 FPS 視角模型,看起來很奇怪、無法動畫化,而且(JPG 沒有 alpha)會渲染成一個黑色方塊。將一個真實的 3D 視角模型作為覆蓋渲染圖層的父物件,掛載到攝影機上。
  • 保留圖片生成僅用於平面 2D 素材(紋理、天空/選單背景、2D 精靈、UI 美術)。絕對不要使用生成的圖片作為 3D 網格、視角模型或角色替代品 — 請使用 3D 幾何 / glTF 建立這些。 在繪製到 canvas/紋理的圖片上設定 crossOrigin="anonymous"。 參閱 imagine-grok-build 技能(僅限 2D — 圖片工具無法產生真正的 3D)。
  • 引擎就緒的遊戲美術原則 → 開啟 game-asset-core(../game-asset-core/)了解預設值 + 盲驗證 + 重試紀律,然後打開對應的專家技能:game-animation-frames(迴圈 / 運動法則)、game-tilesets、game-character-consistency、game-ui-icons。這些是品管/原則,而非匯出管線。在需要真實美術時,不要提供火柴人佔位符。
  • 2D 遊戲精靈 / 動畫工作表 → 執行 generate2dsprite(.grok/skills/generate2dsprite/SKILL.md):純色 #FF00FF 洋紅 imagine_text_to_image 工作表 + 色度後處理腳本(處理器需要洋紅)。將透明的 PNG/GIF 接線到 Canvas/Phaser。仍須套用 game-asset-core(以及在適當時套用動畫/角色專家技能)。
  • 2D 地圖 / 關卡 / 道具包 → 開啟 generate2dmap(.grok/skills/generate2dmap/SKILL.md)。對於可遊玩地圖,偏好僅提供基礎基底 + 獨立道具/碰撞。瀏覽器預設:raw_canvas / Phaser。可拼貼的地面/牆壁 → 也請使用 game-tilesets 進行 2×2 接縫檢查。
  • 可選的密集運動 → 執行 video2dsprite(Grok 的 imagine_image_to_video + 沙箱腳本;洋紅基底)。對於清晰的生產主角,偏好使用 generate2dsprite。使用 game-animation-frames 了解迴圈/翻轉測試法則;在此沙箱中,偏好使用 video2dsprite 而非 ad-hoc 的純 ffmpeg 擷取。

7. 音訊、存檔、手感

  • 音訊:在首次使用者互動(點擊開始)時解鎖 AudioContext,否則 iOS 會靜音;在 visibilitychange 時重新恢復。(references/audio.md)
  • 存檔:localStorage/IndexedDB,帶有 version 欄位 + 遷移。
  • 手感:螢幕震動、擊停、緩和補間、粒子 — 成本低廉,但能顯著提升感知品質。保持呈現與模擬分離。

8. 行動裝置

  • 區分 canvas 緩衝區大小與 CSS 大小;尊重 devicePixelRatio。
  • touch-action: none,以信箱模式適應基礎解析度,處理方向。
  • 觸控控制(虛擬搖桿 + 動作按鈕),目標 ≥44px。

堆疊 / 引擎選擇

  • 3D → three.js,理想情況下透過 @react-three/fiber + drei(適用於 React 應用程式;drei 提供指標鎖定/控制項/載入器)+ @react-three/rapier 用於物理/角色控制器。參見 references/3d-libs.md。
  • 2D → 對於貪食蛇、俄羅斯方塊、Flappy Bird、平台遊戲,原生 Canvas 2D 已足夠;僅在遊戲類型需要時才使用 Phaser。
  • 這些遊戲依賴項未預先安裝 — 請使用 npm install 安裝它們(並確保它們出現在 package.json 中,以便 Vercel 建置可以使用它們)。

完成標準(在「完成」之前)

  • 載入時無主控台錯誤;有可見的遊戲玩法(非空白畫布)。
  • controls 技能自我測試通過(從追蹤攝影機向前移動時 A = 左 / D = 右;如果反轉則翻轉其中一個方向)。不僅僅是截圖。
  • 3D 直立及攝影機一致性自我測試通過(§3, §4)。
  • 在行動裝置視口上使用觸控控制執行。
  • 生產建置(npm run build)呈現建置輸出,而不僅僅是開發模式。
  • 分享 / X 卡片: 開啟 og 技能 — 自訂的 public/og.jpg 以及在 src/lib/og/site.json 中設定 "type": "x:game"。X 使用 og:type="x:game" 將 unfurl 呈現為遊戲卡片;請勿為此使用 twitter:card 或發明 x:type。當 Canvas 應用程式省略 site.json 欄位時,browser-smoke / brand-check 會發出警告。

Individual skills in this repo

This repo contains 17 individual skills — each has its own dedicated page.

evalix098/tiktoklive

Add user accounts and sign-in to this TanStack Start app. Use when the app needs authentication, sign-in, user accounts, protected routes, or per-user data. Triggers on "auth", "login", "log in", "sign in", "sign up", "account", "users", "authentication", "protected", "who is logged in", "current user", "per-user".

evalix098/tiktoklive

Player-facing input signs for browser games: WASD, vehicles, flight, FPS mouse-look, and the #1 failure mode (inverted A/D). Mandatory control self-tests and a tiny test interface so you can verify A turns left before shipping. Load for ANY game with movement, steering, flying, driving, tanks, boats, mechs, drones, planes, karts, third-person follow cams — not only racing. Triggers on "controls", "WASD", "inverted", "steer", "flight", "airplane", "kart", "vehicle", "yaw", "roll", "pitch", "mouse look", "A/D".

evalix098/tiktoklive

Design and build polished, non-generic UI for this TanStack Start + React + Tailwind v4 + shadcn/Radix app. Use whenever you create or restyle any interface surface — pages, landing pages, dashboards, forms, modals, nav, and game overlays (start screens, HUD, menus). Covers design tokens, layout, typography, color, spacing, motion, and the anti-"AI-slop" rules that keep output from looking generic. Triggers on "design", "UI", "make it look good", "polish", "landing page", "theme", "style", "redesign", "ugly", "clean up".

evalix098/tiktoklive

Deep guide for game ANIMATION assets: motion cycles, action keyframes, effect sequences, and animation sprite sheets — built around a video-first pipeline. In this app-builder sandbox, execute via the video2dsprite / generate2dsprite skills (magenta + scripts), not ad-hoc ffmpeg. Use whenever generating anything that moves: walk/run cycles, attacks, idles, FX, flags, fire, animation sheets. Complements game-asset-core.

evalix098/tiktoklive

Core discipline for ANY game-asset generation with Imagine tools: the engine-ready defaults users don't state, spec checklists, style anchoring, read-back verification, honest defect flagging. Use whenever generating any game art (sprites, sheets, animations, tiles, UI, FX) — then ALSO load the matching specialist skill: game-animation-frames for anything that moves, game-tilesets for tiles/terrain, game-character-consistency for recurring characters, game-ui-icons for UI and icons.

evalix098/tiktoklive

Deep guide for CHARACTER IDENTITY across images: turnarounds (front/side/ back), state and damage variants, palette swaps, equipment changes, and same-character-in-context sets. Use whenever generating character turnarounds, character sheets, variants of an existing sprite, or any same-subject multi-image set. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game TILE assets: seamless tileable textures, terrain transition tilesets, autotiles, and ground/platform tiles. Use whenever generating tileable textures, tilesets, terrain transitions, or seamless patterns. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game UI assets: buttons with interaction states, panels, bars, wordmark logos, and icon sets. Use whenever generating game UI elements, HUD assets, inventory icons, icon sets, buttons, or title logos. Complements game-asset-core.

evalix098/tiktoklive

Generate production-oriented 2D game maps with `imagine_text_to_image`: RPG/top-down maps, side-scroller parallax stages, tilemaps, layered raster maps, prop packs, collision zones, and walkable areas. Use when building browser games that need real map art (not pure code-drawn tiles), layered props, or map collision metadata. Triggers on "map", "level", "stage", "tilemap", "overworld", "dungeon", "side scroller background", "prop pack", "2D map".

evalix098/tiktoklive

Generate and postprocess 2D game sprites and animation sheets: pixel-art characters, NPCs, creatures, spells, projectiles, impacts, props, summons, and transparent PNG/GIF exports. Use when building browser games that need real sprite sheets (not code-drawn placeholders), matching a map art style, or producing magenta-background sheets for chroma-key cleanup. Triggers on "sprite", "sprite sheet", "animation sheet", "pixel art character", "walk cycle", "attack animation", "projectile sprite", "2D game asset".

evalix098/tiktoklive

How to use the Imagine tools in Grok Build: imagine_text_to_image, imagine_image_to_image, imagine_reference_to_image, imagine_text_to_video, imagine_image_to_video, imagine_reference_to_video, and render_file for chat previews. When to build a visual with code instead of generating it, prompt-craft, reference-first handling of real people, factual grounding, and asset-consistency. Load this whenever generating or editing an image or video is on the table. Tool-usage-driven, not triggered by a user merely mentioning images.

evalix098/tiktoklive

Peer-to-peer realtime multiplayer over WebRTC data channels: every user of the deployed app connects directly to every other user (full mesh), the server only brokers the handshake at /api/rtc. Lowest possible latency, zero per-message server cost. Use for 2-8 player co-op/casual realtime: shared cursors, drawing, party games, casual action. Triggers: p2p, peer to peer, webrtc, low latency multiplayer, direct connection.

evalix098/tiktoklive

Use Neon Postgres (the database) in this TanStack Start app. Use when the app needs to store or query data, persist state, or keep per-user data. Triggers on "database", "Postgres", "Neon", "save data", "store data", "persist", "tables", "SQL", "query", "migrations".

evalix098/tiktoklive

Share-link previews and app identity for apps on *.grok.me: the injector-owned og:image card, the SVG favicon, and PWA icons for installable apps. Use when scaffolding, renaming, or restyling the app — and for share / unfurl / OG / Twitter card questions. A custom 1200×630 card from the app's own art is the default — games of every kind (DOM board/word games included), whimsical apps, creative tools, and brand-forward pages; only plain utilities keep the placeholder. Always run the brand-asset pass as a `task` subagent and never wait for it. Triggers on "share", "rename", "app name", "OG", "Open Graph", "twitter card", "unfurl", "og:image", "og:type", "x:game:image", "x-banner", "link preview", "social card", "thumbnail", "preview image", "favicon", "app icon", "PWA", "manifest", "installable", "home screen", "SEO", "meta description".

evalix098/tiktoklive

Official Three.js API and TSL (Three.js Shading Language) reference for LLM code generation. Load when writing or debugging three.js / WebGL / WebGPU / custom materials / shaders / GLTF / advanced three APIs beyond basic game loop/controls. Prefer building-games for game correctness (loop, WASD, camera, orientation); use this skill for full API/TSL depth. Triggers on "three.js", "threejs", "WebGPU", "TSL", "NodeMaterial", "shader", "GLTF", "MeshStandard", "OrbitControls", "WebGLRenderer".

evalix098/tiktoklive

Grok Build only. Turn a 2D character still into denser animation sprites via imagine_text_to_image base → imagine_image_to_video (6s/10s run-in-place) → ffmpeg frames → magenta chroma-key → dense sampled strips/grids/GIFs. Use when the user wants video-to-sprite, smoother run/walk cycles, or denser intermediate poses. Prefer generate2dsprite for crisp production pixel sheets. Triggers on "video to sprite", "imagine_image_to_video sprite", "dense walk cycle", "smooth run animation from video".

evalix098/tiktoklive

Call the xAI API (Grok) from this app's server code using the injected XAI_API_KEY: chat/LLM features, image and video generation (Imagine), and voice (text-to-speech). Use when the app needs any "AI" / "assistant" / "chatbot" / "Grok" functionality, runtime image/video generation, or speech. Triggers on "AI", "LLM", "chatbot", "assistant", "Grok", "xAI", "generate text", "summarize", "generate image", "AI video", "voice", "text to speech", "TTS", "OpenAI" (use xAI instead).

相關技能