【发布时间】:2015-05-18 08:43:35
【问题描述】:
我正在尝试创建 2d 游戏,现在我需要游戏宽度。我尝试使用 Gdx.graphics.getWidth() 但这给了我一个空指针。在网上搜索后,我发现了这个 http://www.badlogicgames.com/forum/viewtopic.php?f=15&t=13984 这就是解释,但正如您在我的代码中看到的那样,我使用的是常量和缩放。下面的代码是我的一位队友写的,所以我不想改动太多。但是,有人可以向我解释如何从这种情况下获得游戏的宽度吗?谢谢
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import edu.chalmers.RunningMan.RunningMan;
import static edu.chalmers.RunningMan.utils.Constants.V_HEIGHT;
import static edu.chalmers.RunningMan.utils.Constants.V_WIDTH;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = RunningMan.TITLE;
config.width = V_WIDTH * RunningMan.SCALE;
config.height = V_HEIGHT * RunningMan.SCALE;
new LwjglApplication(new RunningMan(), config);
}
}
【问题讨论】:
标签: java nullpointerexception get libgdx