开发游戏

发布于 2024-12-04 09:51:07 字数 375 浏览 1 评论 0原文

我正在使用 libgdx 框架开发游戏。我想在暂停游戏时引发对话,并且在该对话中我想使用恢复按钮。我知道我应该使用 pause()resume() 方法,但我无法理解应该在这些方法中编写什么。

任何帮助将不胜感激。

我的代码:

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}

I am developing a game using libgdx framework. I want to raise a dialogue when I pause the game, and on that dialogue I want to use a resume button. I know that I should use pause() and resume() methods, but I'm not able to understand what I should write in those methods.

Any help would be apprechiated.

My code:

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七色彩虹 2024-12-11 09:51:07

我认为您很困惑,回调函数中指示的暂停和恢复状态与您的游戏或游戏是否正在“玩”无关。当操作系统因某种原因决定暂停应用程序时,将使用这些调用。

快速浏览一下 Android 开发人员文档将帮助您解决这些“终身”问题 - 另一方面,您需要以某种方式在游戏中实现自己的暂停和恢复逻辑。

I think you are confused, the pause and resume states indicated in your call back functions have nothing to do with your game or whether the game is 'Playing'. These calls are used when the OS decides to suspend the application for some reason.

A quick look at the android developers documentation will help you with these 'lifetime' issues - on the other hand you need to implement your own pause and resume logic in the game in some way.

暮年慕年 2024-12-11 09:51:07

解决此问题的一种方法是为您的游戏状态(PLAY、PAUSE)创建一个枚举。在主游戏循环中,您可以使用 if else 语句。 if(GameState == PLAY) 更新所有游戏内容。 if(GameState == PAUSE) 更新您的菜单管理器。

通常,在游戏架构中,人们应该使用状态来解决这些类型的问题。游戏架构的另一个规则是让所有游戏实体的行为都与 elapsedTime 相关。这样,无论在什么设备上玩游戏,游戏速度始终相同。我在所有游戏中都使用秒作为小数,因此所有运动都以米每秒为单位。这样我就可以插入真实的物理方程,这样我就不会一直追逐疯狂的数字来试图让事情发挥作用。

在这种情况下,暂停的快速解决方法是在游戏处于暂停状态时将经过的秒数设置为零。这是一个黑客!证明使用状态几乎总是最好的主意,特别是对于诸如游戏类之类的管理器类。

您甚至可以考虑创建一个 GameState 类来负责状态之间的转换。这对于播放声音和启动动画(例如菜单从屏幕顶部向下移动)非常方便,此时游戏既不处于暂停也不处于播放状态;值得深思。

进入移动游戏领域,拥有 TOMBSTONE 和 REVIVE 过渡状态非常适合在设备处理其他应用程序时将游戏临时缓存到存储中。

One way of solving this problem is to make an enum for your game state (PLAY, PAUSE). In your main game loop you can use an if else statement. if(GameState == PLAY) update all gameplay stuff. if(GameState == PAUSE) update your menu manager.

Typically in game architecture one should use states for these types of problems. Another rule of game architecture is to have all game play entities behave in relation to elapsedTime. That way, that rate of game play is always the same no matter what device the game is being played on. I use seconds as a decimal in all of my games so all motion is in meters per second. That way I can plug in real physics equations so I'm not chasing around crazy numbers all the time trying to get things to work.

A quick fix for a pause in this case would be to just set your elapsed seconds to zero when the game is in pause state. This is a hack! proving that using states is almost always the best idea, especially with manager classes such as a game class.

You may even consider creating a GameState class that is responsible for transitions between states. This will be handy for playing sounds and starting animations such as the menu moving down from the top of the screen, in this time the game is in neither PAUSE nor PLAY; food for thought.

Getting into mobile games, having a TOMBSTONE and REVIVE transition states would be perfect for temporarily caching the game into storage while the device handles other applications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文