更小的下載與更快的啟動
首幀只加載它需要的內容。將執行時檔案放在 resources/ 中,並用 asset: URI 引用。它們不會進入 Go 二進位制,Web 目標可以按需獲取。對於載入資源系統前必須可用的小檔案(例如載入畫面圖片或很小的啟動表),使用 //go:embed 或 assets.WithFS。
載入首個小資源組
建立 assets.Manager,為首個場景登記資源組,並在載入期間掛載 assets.LoadingScreen。首幀顯示後再從首個場景啟動其他資源組,避免它們的位元組數拖慢初始畫面。
mgr := assets.NewManager(cx)
first := mgr.Group("first").AddImage("logo", core.Src("asset:ui/logo.png"))
later := mgr.Group("level").AddAtlas("hero", "asset:hero.json", core.Src("asset:hero.png"))
return assets.LoadingScreen{Group: first, View: loadingView, Next: func() core.Node {
later.Load(nil)
return gameView(mgr)
}}
resources/ 檔案會隨釋出包一起提供。可以用 mobile.exclude_resources 從 iOS 和 Android 包中排除僅桌面使用的資源組。可選內容應制作 DLC,並用 go tool game dlc verify 校驗,不要把所有關卡塞進首次下載。
Web 快取與進度
當釋出版本應在首次成功啟動後快取資源時,在 nsgo.yaml 中設定 web.offline。Web 載入器通過 assets.Group.Progress 訊號報告進度,LoadingScreen 也使用同一訊號;可用 LoadingScreen.View 或 LoadingView 替換預設介面。nsgo build 會寫出 WebAssembly 的 Brotli 和 gzip 副本,供伺服器按協商結果傳送。
音訊與預算
音樂和短音效優先使用壓縮的 .ogg、.m4a 或 .mp3,避免 WAV。釋出到商店前執行 go tool game size -kind wasm -budget benchmarks/web-budget.json 以及 AAB、IPA 預算檢查。報告會列出最大檔案和分類,便於定位首個資源組或新依賴帶來的成本。