AssetManager在LibGDX [英] AssetManager in LibGDX

查看:115
本文介绍了AssetManager在LibGDX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 AssetManager 类LibGDX,我理解它是如何工作的,但我想实现一个载入画面。我按照 AssetManagerTest.java 文件<一个href="http://$c$c.google.com/p/libgdx/source/browse/trunk/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java">here, 但我有一个困难时期试图找出如何得到它才能正常工作。有人能指出我朝着正确的方向吗?我的目标是要加载的资产(纹理,声音,字体,...等),并更新一间酒吧,完成百分比在屏幕上。我不明白的 ResolutionFileResolver 第[] 在我提供的链接。它们是什么呢?我的目标是支持静态类,可以给我使用,我需要在我的游戏在任何屏幕上的资产。是否有一个preferred的方法来做到这一点?谢谢你。

I am trying to use the AssetManager class in LibGDX and I understand how it works but I am trying to implement a loading screen. I have followed the AssetManagerTest.java file here, but I am having a hard time trying to figure out how to get it to work correctly. Can someone point me in the right direction? My goal is to load the assets (textures, sounds, fonts, ... etc) and update a bar with the percentage complete on the screen. I don't understand the ResolutionFileResolver and the Resolution[] in the link I provided. What are they for? My goal is to support a static class that can give me access to all of the assets I need in my game from any screen. Is there a preferred method to do this? Thanks.

推荐答案

在查看源的<一个href="http://$c$c.google.com/p/libgdx/source/browse/trunk/gdx/src/com/badlogic/gdx/assets/loaders/resolvers/ResolutionFileResolver.java">ResolutionFileResolver还有其他的解析器,我认为这只是加载纹理最匹配屏幕分辨率的方式,但比赛正是基于文件名的模式。

After looking at the source for ResolutionFileResolver as well as the other 'resolvers', I think it's just a way of loading textures that best match the screen resolution, but the match is just based on filename patterns.

因此​​,在 AssetManagerTest ,他有纹理,屏幕尺寸小320x480,480x800的,并为480x854。它看起来像每个组的纹理应该是在一个名为0.​​320480或0.480800或目录0.480854(虽然名字可以是任何你想要的,如低,高和宽如果这些是你的目录),和​​他指定创建解析器对<一个数组时,这一切信息href="http://$c$c.google.com/p/libgdx/source/browse/trunk/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java#56">line 56 测试。

So in AssetManagerTest, he's got textures for screen sizes 320x480, 480x800, and 480x854. It looks like each group of textures should be in a directory called ".320480" or ".480800" or ".480854" (although the name can be anything you want, like "low", "high", and "wide" if those are your directories), and he specifies all this info when creating the array of resolvers on line 56 of the test.

在做这些东西的好处是,当他叫<一href="http://$c$c.google.com/p/libgdx/source/browse/trunk/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java#91"><$c$c>manager.load(),他只是挑选出像数据/ animation.png文件名。那么解析器发现的纹理包最符合当前屏幕分辨率,并加载一个。

The advantage of doing all this stuff is that when he calls manager.load(), he just picks out a filename like "data/animation.png". Then the resolver finds the pack of textures that most closely matches the current screen resolution, and loads that one.

我觉得这个例子的其余部分应为pretty的明确,至少在 AssetManager 的基础知识。创建一个管理者,集加载器,调用负载(),呼叫的get()来使用它,然后调用卸载()完成后。

I think the rest of the example should be pretty clear, at least for the basics of AssetManager. Create a manager, set the loader, call load(), call get() to use it, and then call unload() when done.

有关更新进度条,你只需要到手动之后每次调用加载做。

For updating a progress bar, you'll just need to do that manually after each call to load.

和使用静态类资产的管理无疑是一种可能性。另一个类似的方法是只使用一个单例。它有它的仇敌,但我认为在一个垃圾收集的环境中,它应该是确定一个简单的项目,虽然它是关于同一个公共静态的。

And using a static class for asset management is certainly one possibility. Another similar option is to just use a singleton. It has its haters, but I think in a simple project in a garbage collected environment it should be ok, although it's about the same as a public static.

另一种选择 - 也许是最好的? - 是使用具有游戏全局的静态副本一个基类,然后所有其他游戏类继承它。这是在副本岛使用的方法。请参阅<一href="http://$c$c.google.com/p/replicaisland/source/browse/trunk/src/com/replica/replicaisland/BaseObject.java">base类和<一href="http://$c$c.google.com/p/replicaisland/source/browse/trunk/src/com/replica/replicaisland/ObjectRegistry.java">object注册表。副本岛有很好的注释和值得检查出针对Android和放大器; Java游戏。

Another option--maybe the best?--is to use a base class that has a static copy of your game globals, and then all other game classes inherit from it. This is the approach used in Replica Island. See the base class and the object registry. Replica Island is well commented and worth checking out for Android & Java games.

这篇关于AssetManager在LibGDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆