在 AndEngine 中加载纹理时的进度条
当我开始游戏时,黑屏会出现一段时间,因为正在加载资源。 我仔细阅读了一个教程,该教程展示了如何在引导资源的同时显示进度条,我遵循了它,现在我可以看到进度条。但问题是,当进度条可见时,其他所有事情都会停止。但什么也没发生。只有黑屏和进度条。谁能告诉我为什么每件事都暂停以及为什么 loadresources 和 loadscene 方法不起作用?请提供解决方案。
when I start my game black screen comes for a while because resources are being loaded.
I went thorough a tutorial which show how to show progress bar while leading resources I followed it and now I can see progress bar. But the problem is this when progress bar is visible every thing else is stopped. And nothing happens. Only a black screen and a progress bar on it. Can any one tell me why every thing is paused and why loadresources and loadscene methods are not working? Please provide a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在工作线程中加载资源。执行此操作的一个不错的实用程序是 AsyncTask。指南主题 进程和线程 解释了原因您需要这样的东西,以及演示如何执行简单的
AsyncTask
的示例代码,这可能正是您所需要的。You need to load your resources in a worker thread. A nice utility for doing this is AsyncTask. The guide topic Processes and Threads has an explanation of why you need something like this, as well as sample code showing how to do a simple
AsyncTask
that might be just what you need.来自 Engine.java:
这就是引擎挂起且 UI 卡住的原因。可以在纹理加载到硬件时显示加载屏幕,而不会冻结,比如说
ProgressBar
。这并不容易,需要大量代码,但它是可能的,不需要疯狂的黑客,只需要一些逻辑。您需要有一个资源管理器(RM)和一个场景管理器 (SM) 协同工作(与
AsyncTasks
)并负责加载当前场景的纹理。由于您有一个BaseGameActivity
,您可以使用此Activity
实例来显示带有进度条的全屏Dialog
。逻辑是:Dialog
由于texture.load 不能保证纹理实际加载,因此您需要有一个
TryToDismissDialog
那个扩展TimerTask
。此TryToDismissDialog
会不时查询场景 A 纹理并检查它们是否实际已加载:如果所有纹理均已加载,您将关闭
Dialog< /code> 瞧,你会看到场景准备好了。
希望有帮助
ps:这实际上涉及一些代码行,我刚刚在这里发布了快速步骤/指南/伪代码。我不会发布最终的解决方案,因为它非常重并且“与项目相关”。
From Engine.java:
And that's why the engine hangs and the UI gets stuck. It's possible to display a loading screen while the textures are being loaded into hardware, without freezing, let's say, a
ProgressBar
. It's not easy and requires a lot of code, but it's possible and doesn't require crazy hacks, just some logic.You need to have a Resources Manager (RM) and a Scene Manager (SM) who work together (with
AsyncTasks
) and are responsible for loading the textures for the current scene. Since you've aBaseGameActivity
you can use thisActivity
instance to show a fullscreenDialog
with the progress bar. The logic is:Dialog
Since texture.load doesn't guarantee the texture is actually loaded you'll need to have a
TryToDismissDialog
that extendsTimerTask
. ThisTryToDismissDialog
from time to time will query the Scene A textures and check if they are actually loaded:If all textures are loaded you dismiss the
Dialog
and voilá you'll see the Scene ready.Hope it helps
ps: this actually involves some lines of code, I've just posted here a quick steps/guide/pseudo-code. I'll not post the final solution because it's quite heavy and "project related".