java - 加载资源 LibGDX HTML (GWT) 的良好实践

标签 java gwt libgdx assets

由于 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/

相关文章:

java - 在运行时停止 Akka actor

java - 怎么能不在本地使用activemq呢?

gradle - 无法将 admob 添加到 libgdx 项目

java - 从 double 到 float 的可能有损转换

java - libgdx 地面不起作用

java - Spring 不会调用 Hibernate validator 来验证方法参数

java - 尝试将 Azure 政府端点与 Azure 存储 Java 库一起使用时出错

java - Eclipse 中带有 WindowBuilder 的应用程序窗口

GWT:将 UIBinder 与 HTML 模板一起使用......如何让它工作?

gwt - 无法获取 GWT CellTable 的行单击处理程序