进度栏加载纹理在AndEngine [英] Progress bar while loading Textures in 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.
推荐答案
从Engine.java:
From Engine.java:
public void onDrawFrame(final GLState pGLState) throws InterruptedException {
final EngineLock engineLock = this.mEngineLock;
engineLock.lock();
try {
engineLock.waitUntilCanDraw();
this.mVertexBufferObjectManager.updateVertexBufferObjects(pGLState);
this.mTextureManager.updateTextures(pGLState);
this.mFontManager.updateFonts(pGLState);
this.onUpdateDrawHandlers(pGLState, this.mCamera);
this.onDrawScene(pGLState, this.mCamera);
engineLock.notifyCanUpdate();
} finally {
engineLock.unlock();
}
}
这就是为什么发动机挂起和用户界面卡。这是可能的,而纹理加载到硬件,不结冰,显示加载屏幕,让我们说,一个进度
。这并不容易,需要大量的code,但它是可能的,并不需要疯狂的黑客,只是一些逻辑。搜索结果
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.
您需要有一个资源管理器(RM)和场景管理器(SM)谁一起工作(与 AsyncTasks
),并负责加载纹理当前场景。因为你已经在 BaseGameActivity
您可以使用此活动
实例显示全屏对话框
通过进度条。其中的逻辑是:
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 a BaseGameActivity
you can use this Activity
instance to show a fullscreen Dialog
with the progress bar. The logic is:
- SM被要求出示的场景
- SM显示加载
对话框
- SM异步告诉RM到所有的场景资源加载到硬件(每个纹理场景,texture.load)
- RMonSceneTexturesLoadComplete讲述SM所有纹理加载
- SM is asked to show Scene A
- SM shows the loading
Dialog
- SM asynchronously tells the RM to load all Scene A resources into hardware (for each texture for Scene A, texture.load)
- RM "onSceneTexturesLoadComplete" tells SM that all textures are loaded
由于texture.load不保证纹理实际加载你需要有一个 TryToDismissDialog
扩展的TimerTask
。这 TryToDismissDialog
不时会查询场景纹理和检查,如果他们实际上是加载:结果
Since texture.load doesn't guarantee the texture is actually loaded you'll need to have a TryToDismissDialog
that extends TimerTask
. This TryToDismissDialog
from time to time will query the Scene A textures and check if they are actually loaded:
if (texturePack.getTexture().isLoadedToHardware()) {
texturesLoaded++;
}
如果所有纹理加载您关闭对话框
,瞧你会看到现场准备就绪。结果
希望它可以帮助搜索搜索结果
PS:这实际上涉及到code的一些行,我刚刚在这里发表简单的步骤/引导/伪code。我不会发布最终的解决方案,因为它是相当沉重,项目相关的。
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".
这篇关于进度栏加载纹理在AndEngine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!