Android游戏编程问题
我正在使用 Lunar Lander 作为教程开发一款游戏,我有几个问题。
在我的游戏中:
- 当我按 Home 键时,会调用 onPause() 。当我单击游戏图标返回时,我会看到游戏屏幕,但一切都被冻结了。
- 当我按下返回键时, onPause() 被调用。当我单击游戏图标返回时,我看到一个空白屏幕。
- 在这两种情况下,我都没有看到 onResume() 方法被调用。
所以我很困惑为什么会发生这种情况。看看Lunar Lander,没有onResume()。这是为什么?既然游戏线程在onPause()中停止了,那么它如何再次启动呢?
在我的游戏中,我不确定为什么 onResume() 没有被调用,但我认为它永远不会到达那里,因为存在某种冻结。
月球着陆器代码或我的代码是否缺少某些内容? LL 代码是否正确处理状态更改?最后,是否有更好的网络教程来处理游戏的状态变化?
谢谢!
I am developing a game using Lunar Lander as a tutorial, and I have a couple questions and a problem.
In my game:
- when I press the Home key, onPause() is called. When I click my game's icon to go back in, I get the game screen, but everything is frozen.
- when I press the Back key, onPause() is called. When I click my game's icon to go back in, I get a blank screen.
- In both cases, I do not see my onResume() method being called.
So I am confused as to why this is happening. Looking at Lunar Lander, there is no onResume(). Why is that? Since the game thread is stopped in onPause(), how does it start up again?
In my game, I am not sure why onResume() is not being called, but I assume that it never get there since there is some sort of freeze.
Is the Lunar Lander code, or my code, missing something? Does the LL code handle state changes correctly? Finally, is there a better web tutorial for handling state changes for games?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

在这两种情况下,我认为当您单击应用程序图标时,会在第一个实例之上启动一个新活动。我想说的是,android 文档对此并不清楚,但是如果您想确保应用程序的根活动仅在您需要添加:
作为应用程序清单中活动的属性时才实例化。
In both cases, I suppose a new activity is launched on top of the first instance when you click on your application icon. I would say the android documentation is not that clear about it, but if you want to make sure the root activity of your application is only instantiated once you need to add:
as a property for the activity in your application manifest.