air - ACTIVATE/DEACTIVATE 事件不适用于使用 Starling 框架的移动游戏应用
问题描述
所以我正在使用starling框架开发一个手机游戏,我希望游戏在我点击手机上的主页/返回按钮时暂停,当然在回到游戏时恢复。我做了一些研究,并尝试了以下方法:
this.addEventListener(FlashEvent.DEACTIVATE, stopGame);
this.addEventListener(FlashEvent.ACTIVATE, continueGame);
private function continueGame(event:FlashEvent):void
{
...
}
private function stopGame(event:FlashEvent):void
{
...
}
我不得不添加一个名为 FlashEvent 的新类,它扩展了 flash.events.Event,因为我在同一个类中使用了 starling Event 和 flash Event,而当我使用 flash.events.Event 时,我得到了这个错误:
Error: Access of undefined property flash
starling.events.Event 也是如此。
所以我使用了上面的代码并在我的手机上进行了尝试,但是当我返回/home 时,游戏继续进行,音乐继续播放。
我的问题是:在空中移动应用程序中调度激活/停用事件的正确方法是什么?
解决方案
在您的主要启动课程中使用。(请注意,在本例中,'app:Main' 是我调用 Starling 启动方法的类。
请注意,您应该使用以下内容确定事件类:starling.events.Event.XXX flash.events.Event.XXX
_mStarling.addEventListener(starling.events.Event.ROOT_CREATED,
function onRootCreated(event:Object, app:Main):void
{
_mStarling.removeEventListener(starling.events.Event.ROOT_CREATED, onRootCreated);
app.start(assets);
_mStarling.start();
NativeApplication.nativeApplication.addEventListener(
flash.events.Event.ACTIVATE, function (e:*):void {
_mStarling.start();
try {
// optionally call some other methods
} catch(e:Error) {
}
});
NativeApplication.nativeApplication.addEventListener(
flash.events.Event.DEACTIVATE, function (e:*):void {
try{
// optionally call some other methods before stopping
} catch(e:Error) {
}
_mStarling.stop();
});
});
推荐阅读
- google-cloud-platform - 部署时云函数抛出错误
- flutter - 在 Flutter 中隐藏文本字段中的某些字符
- ios - 在 Xcode 中显示 AdMob gdpr 同意书
- python - 2020 年谷歌编码挑战题:未指明的单词
- vbscript - 了解 VBS 多行符号
- node.js - 创建 S3 存储桶 nodejs 时出现 aws-sdk 问题
- java - ViewPager2 中的折叠工具栏会导致滚动问题
- git - git ftp 推送/克隆的问题
- python - 如何在 Python 中将字典分配给另一个字典的每个值?
- c# - c# web api派生类型未序列化