ctx.game 提供当前作品及宿主窗口相关能力。

API

方法或属性返回值说明
exit()voidPlayer 中退出游戏;Studio Preview 中结束播放
title()string获取当前作品标题
window.canFullscreen()boolean查询宿主是否支持全屏
window.getFullscreen()Promise<boolean>读取全屏状态
window.setFullscreen(value)void | Promise<void>设置全屏状态
window.toggleFullscreen()void | Promise<void>切换全屏状态
window.useFullscreen()[boolean, setter]React Hook;订阅全屏状态

案例:显示作品标题并切换全屏

输入: 当前作品标题为“星河彼岸”,宿主支持全屏且当前处于窗口模式。
const title = ctx.game.title();
const supported = ctx.game.window.canFullscreen();
const before = await ctx.game.window.getFullscreen();

if (supported) {
  await ctx.game.window.setFullscreen(true);
}

const after = await ctx.game.window.getFullscreen();
console.log({ title, supported, before, after });
输出:
{
  "title": "星河彼岸",
  "supported": true,
  "before": false,
  "after": true
}
不支持全屏的宿主中,setFullscreen() 是安全的空操作。调用 exit() 前应先完成必要的保存和确认流程。