Game onPause 方法
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
onPause(callback: () => void): void;
订阅 pause 事件。
示例
GameSnacks.game.onPause(() => {
// Display pause screen.
engine.scene("pauseScreen").setVisible();
engine.loop.sleep();
});
要求
- 游戏必须在调用
callback
时暂停所有执行,并且仅在调用 onResume
的 callback
时才能恢复执行。这一要求适用于所有游戏行为,包括:游戏循环、声音、音乐、互动、网络调用和渲染。
- 游戏不得使用 Page Visibility API 或类似 API,只能使用这些 GameSnacks SDK 方法。
- 游戏应该在调用
callback
时保存用户进度。
- 如果游戏暂停,必须明确告知用户。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-28。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-28。"],[[["Subscribes to pause events, allowing developers to execute code when the game is paused."],["Requires pausing all game execution, including game loops, sounds, interactions, and network calls, resuming only upon receiving the `onResume` callback."],["Recommends saving user progress when the pause event occurs and providing clear visual indication to the user."],["Emphasizes exclusive use of GameSnacks SDK methods for pause/resume functionality, prohibiting reliance on Page Visibility API or similar alternatives."]]],[]]