由于 GWT HTML5 部署,我正在创建一个主要在浏览器上运行的游戏。我在图像和声音之间有相当多 MB 的资源。显然我并不总是需要它们。我想根据接下来出现的屏幕和其他参数来加载它们。这一点特别重要,因为我的主要部署将在网络上(启动时无法加载所有 50MB,以防它们被使用)。
我真的不知道资源加载在 HTML5 上的 LibGDX 上是如何工作的。我想使用 AssetManager 或类似的东西来加载我的 TextureAtlases 和声音,但我认为 HTML5 部署只是在开始时加载所有内容,无论我以后是否在核心项目中使用 AssetManager。
使用 libGDX 和 GWT 的正确 Assets 加载管道是什么。从核心项目加载所有内容会很棒,因为这种方式将来会是多平台的,但现在并不重要,因此重要的部分是在网络上明智地加载资源。
提前致谢。
最佳答案
我推荐的 Assets 管理方式:
// load texture atlas
final String spriteSheet = "images/spritesheet.pack";
assetManager.load(spriteSheet, TextureAtlas.class);
// blocks until all assets are loaded
assetManager.finishedLoading();
// all assets are loaded, we can now create our TextureAtlas object
TextureAtlas atlas = assetManager.get(spriteSheet);
// (optional) enable texture filtering for pixel smoothing
for (Texture t: atlas.getTextures())
t.setFilter(TextureFilter.Linear, TextureFilter.Linear);
现在加载你要做的 Sprite :
// Create AtlasRegion instance according the given <atlasRegionName>
final String atlasRegionName = "regionName";
AtlasRegion atlasRegion = atlas.findRegion(atlasRegionName);
// adjust your sprite position and dimensions here
final float xPos = 0;
final float yPos = 0;
final float w = asset.getWidth();
final float h = asset.getHeight();
// create sprite from given <atlasRegion>, with given dimensions <w> and <h>
// on the position of the given coordinates <xPos> and <yPos>
Sprite spr = new Sprite(atlasRegion, w, h, xPos, yPos);
关于java - 加载资源 LibGDX HTML (GWT) 的良好实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27157852/