如何使用 Startactivity 并使调用 Cocos2d 层保持活动状态 (Android/Java)?
我正在尝试使用 Cosos2d for Android 框架 (Java) 将我的 iPhone Cocos2d 游戏移植到 Android。
当我从主要活动启动 PreferenceActivity 时遇到问题。这是我的设置:
(1)HelloWordActivity.java: 初始化Cocos2d环境并启动GameLayer.scene
(2)Gamelayer.scene: 向用户展示游戏,但也有一个按钮来显示从 Gamelayer 类调用的设置面板,如下所示:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(helloworldactivity, ShowSettingsActivity.class.getName());
helloworldactivity.startActivity(intent);
这显示了首选项活动很好,但是当关闭首选项并返回到我的游戏时,它似乎没有持续存在(它被重新加载/重新启动并且不保留其状态)。
如何在不破坏 Cocos2d 中当前游戏会话的情况下向用户呈现标准的 Android 首选项屏幕?
I'm trying to port my iPhone Cocos2d game to Android using the Cosos2d for Android framework (Java).
I'm running into a problem when I start PreferenceActivity from my main activity. This is my setup:
(1) HelloWordActivity.java:
Inits the Cocos2d environment and starts GameLayer.scene
(2) Gamelayer.scene:
Presents the user with the game but also has a button to show the settingspane which gets called from the Gamelayer class like this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(helloworldactivity, ShowSettingsActivity.class.getName());
helloworldactivity.startActivity(intent);
This shows the Preference Activity just fine, but when closing the preferences and returning to my game it appears it did not persist (it get's reloaded/restarted and does not retain it's state).
How can I present the user with a standard Android preferences screen without destroying the current game session in Cocos2d ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从你的课程名称来看,我假设你使用 Dan 的教程作为入门
确保删除 dan 的 onStop() 覆盖方法,该方法在您加载首选项时被调用,并且调用
删除它应该为您完成
我确实注意到您放弃并切换到 andEngine ,这也是一个不错的引擎,但我认为无论如何我都会回答这个问题
from the names of your classes , I'm assuming you used Dan's tutorial as a starter
make sure you remove dan's onStop() override method , that gets called when you are loading the preferences and it calls
removing this should do it for you
I did notice that you gave up and switched to andEngine , that's a nice engine too but I thought I'd answer this one anyway
您需要获取主要活动才能开始新活动,我希望此代码对您有所帮助
You need to get the main activity to start new activity, I hope this code will help you