相同级别数据的不同纹理

时间:2016-07-06 03:14:39

标签: java libgdx textures assets

下面的代码显示了我的Assets类,它允许我加载一次纹理并在全局需要时调用它。如果你看到我的包被称为house1.pack意味着将有不止一个具有不同艺术风格的房子。我想知道我是否可以使用我当前的代码和小调整来实现类似于流行的应用程序Clash Royale的设计。我希望在游戏中根据玩家等级加载不同的.pack文件。不同的房屋具有相同的对象,具有相同的png文件名和大小,但它们的绘制方式不同。

谢谢,

Denfeet

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 {
...
}

}

1 个答案:

答案 0 :(得分:0)

您可以随时加载和卸载资产。如果您不想在游戏中的任何其他地方使用house1.pack,您可以:

assetManager.unload("TexturePacker/house1.pack")

处理你的house1.pack,然后再用你的init()方法做的大部分工作

assetManager.load("TexturePacker/house2.pack", TextureAtlas.class);
assetManager.finishLoading();
//etc

不确定如何构建代码,但以上是这个想法。根据您所谈论的资产数量(加载时间),您可能需要一个自然转换点(不一定是完整加载屏幕)。但是如果你想动态地将纹理从一个房子改变到另一个房子,你可能想要在开始时一次性加载它们并找到一种不同的方法来交换它们。

相关问题