【问题标题】:AssetManager libgdxAssetManager libgdx
【发布时间】:2013-10-19 22:11:27
【问题描述】:

我正在尝试为我的游戏制作加载页面。 我的代码是这样的:

manager = new AssetManager();
game = new Game(level);
game.startLoadingTextures(manager);

public void startLoadingTextures(AssetManager manager){
    manager.load("data/background.png" ,Texture.class);
}

在更新函数中我有这个:

if (manager.update()){
    game.setTexture(manager);
}

什么是setTexture函数?我从经理那里得到所有的纹理。

public void setTexture(AssetManager manager) {
    System.out.println("entered here");
    background = manager.get("data/background.png" ,Texture.class);
}

我得到这个错误:

Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.smeurares.game.Loading.update(Loading.java:31)

第 31 行是game.setTexture(manager),在输入函数之前我得到了这个错误,因为System.out.println("entered here"); 没有出现在控制台中。

我做错了什么?

【问题讨论】:

  • game 必须是 null 直到您到达第 31 行。使用调试器并逐步检查您的代码以找出为什么它是 null

标签: java libgdx


【解决方案1】:

哦..没人,就是这样,游戏没有声明..因为它应该是this.game = new Game(level),没有考虑过......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    相关资源
    最近更新 更多