Andengine 屏幕上的暂停按钮
我想在 andengine 中创建一个屏幕暂停按钮
我现在要做的是添加一个精灵,当我触摸它时,我执行 engine.stop() ,问题是引擎不会处理更多触摸事件,直到我恢复游戏(现在我使用菜单按钮来实现),那么有没有办法实现呢?
谢谢!
I want to create an onscreen pause button in andengine
What I do now is add an sprite and when I touch it, I do engine.stop(), the problem with this, is that the engine doesn't handle more touchevents till I resume the game (now I use the menu button for this), so is there a way to achieve it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
看看AndEngine的例子,有一个项目展示了AndEngine中菜单的使用,你会发现除了停止引擎之外还有更好的实现菜单的方法。祝你好运!
Look at the AndEngine's examples, there is a project that shows the use of menus in AndEngine, you'll find a better way of implementing a menu other than stopping the engine. Good luck!
我发现最好的方法是创建一个场景,然后在暂停时设置覆盖 onManagedUpdate 这样
一切都会完美运行,您可以在游戏层上执行此操作并像往常一样更新菜单层,
I found the best way to do it is creating an scene, and when paused, set override the onManagedUpdate this way
This way everything works perfectly, and you can do it on a game layer and have the menu layer updated as usual,
您可以轻松地在屏幕上执行暂停按钮。您需要做的是,在屏幕上的任意位置创建一个暂停按钮,触摸该按钮时,在原始暂停按钮上显示带有播放按钮的 MenuScene。如果您注释掉 PauseMenu 示例中的 .buildAnimations() 代码,则可以将 .setPosition() 用于 MenuItem。
为了演示这个想法,我做了一个简单的活动来展示它的可能性。看看并亲自尝试一下。
链接:https://github.com/reittes/On-Screen-Pause-Button
好运
you can do on screen pause button pretty easily. What you need to do is, create a pause button anywhere on screen, on touching that button, show a MenuScene with play button over the original pause button. You can use .setPosition() for MenuItem if you comment out the .buildAnimations() code from the PauseMenu example.
In order to demonstrate the idea, I've made a simple activity to show its possible. Take a look and try for yourself.
Link: https://github.com/reittes/On-Screen-Pause-Button
GoodLuck
我要做的就是在您的文件中添加一个“暂停”布尔值,然后将按钮将其设置为 true,然后使用
if (!pause) {...}
块包含您的引擎更新程序让它在暂停时停止更新。这不是最优雅的解决方案,但在我的游戏中有效,并且在取消暂停时没有造成性能问题。What I would do is add a "paused" boolean in your file and then have the button set it to true, then encompass your engine updater with a
if (!pause) {...}
block to make it stop updating when it's paused. Not the most elegant solution but worked in my game and caused no performance issues on unpause.伪代码
Psedu code
我创建我的类(MyEngine 扩展 Engine)并
在游戏类中更改并创建 MyEngine 引擎;
I create my class (MyEngine extends Engine) and changed
and create MyEngine engine in game class;