【发布时间】:2016-07-06 03:14:38
【问题描述】:
下面的代码显示了我的 Assets 类,它允许我加载一次纹理并在全局需要时调用它。如果您看到我的包名为 house1.pack,这意味着将有不止一个具有不同艺术风格的房子。我想知道我是否可以通过我当前的代码和微小的调整来实现类似于流行的应用程序 Clash Royale 的设计。我希望在游戏中根据玩家等级加载不同的 .pack 文件。不同的房子有相同的对象,具有相同的 png 文件名和大小,但它们的绘制方式不同。
谢谢,
丹菲特
public class Assets implements Disposable, AssetErrorListener {
public static final String TAG = Assets.class.getName();
public static final Assets instance = new Assets();
private AssetManager assetManager;
public AssetFonts fonts;
public AssetDoor door;
public AssetPlatform platform;
public AssetPlayer player;
public AssetControls controls;
// singleton
private Assets() {
}
public void init(AssetManager assetManager) {
this.assetManager = assetManager;
assetManager.setErrorListener(this);
assetManager.load("TexturePacker/house1.pack", TextureAtlas.class);
assetManager.finishLoading();
TextureAtlas atlas = assetManager.get("TexturePacker/house1.pack");
//create game resource objects
fonts = new AssetFonts();
door = new AssetDoor(atlas);
platform = new AssetPlatform(atlas);
player = new AssetPlayer(atlas);
controls = new AssetControls(atlas);
}
@Override
public void error(AssetDescriptor asset, Throwable throwable) {
Gdx.app.error(TAG, "Couldn't load asset '" + asset.fileName + "'", (Exception) throwable);
}
public class AssetFonts {
...
}
public class AssetPlayer {
...
}
public class AssetControls {
...
}
public class AssetDoor {
...
}
public class AssetPlatform {
...
}
}
【问题讨论】:
标签: java libgdx textures assets