LibGDX 中的 AssetManager [英] AssetManager in LibGDX

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

问题描述

我正在尝试使用 LibGDX 中的 AssetManager 类,我了解它的工作原理,但我正在尝试实现加载屏幕.我遵循了 AssetManagerTest.java 文件 这里,但我很难弄清楚如何让它正常工作.有人可以指出我正确的方向吗?我的目标是加载资产(纹理、声音、字体等)并用屏幕上的完成百分比更新一个栏.我不明白我提供的链接中的 ResolutionFileResolverResolution[].它们是为了什么?我的目标是支持一个静态类,它可以让我从任何屏幕访问我在游戏中需要的所有资产.有没有首选的方法来做到这一点?谢谢.

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.

推荐答案

查看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 的纹理.看起来每组纹理应该在一个名为.320480"或.480800"或.480854"的目录中(尽管名称可以是任何你想要的,比如低"、高"和宽"如果这些是您的目录),他会在 测试的第 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.

做这一切的好处是当他调用manager.load(),他只是选择了一个文件名,比如data/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.

我认为示例的其余部分应该非常清楚,至少对于 AssetManager 的基础知识而言.创建管理器,设置加载器,调用load(),调用get()使用,完成后调用unload().

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.

另一种选择——也许是最好的?——是使用一个基类,该基类具有您的游戏全局变量的静态副本,然后所有其他游戏类都继承自它.这是复制岛中使用的方法.请参阅基类对象注册表.Replica Island 得到了很好的评价,值得一试 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.

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

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