gpt4 book ai didi

java - Java libGdx : FreeTypeFontGenerator is not working (Black screen)

转载 作者:行者123 更新时间:2023-12-03 07:59:15 24 4
gpt4 key购买 nike

我添加了自定义字体Aller_light.ttf,当我尝试运行无错误绘制的字体的程序时,屏幕是黑色的,因此我不确定它是否在屏幕之外的其他地方呈现或完全不呈现。
如果您能给您2美分,那对我来说将是非常有值(value)的。

编辑
现在说我有一个nullPointerExeption

Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.mygdx.finis.states.MenuState.draw(MenuState.java:43)
at com.mygdx.finis.states.GameStateManager.draw(GameStateManager.java:31)
at com.mygdx.finis.Main.render(Main.java:36)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)

This is what should be happening:

MenuState类
package com.mygdx.finis.states;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.mygdx.finis.Assets;
import com.mygdx.finis.Main;

public class MenuState extends GameState{

private SpriteBatch sb;

private BitmapFont font;

private int currentItem;
private String[] menuItems;

protected MenuState(GameStateManager gsm) {
super(gsm);
}

public void init() {

sb = new SpriteBatch();

FreeTypeFontGenerator gen = new FreeTypeFontGenerator(
Gdx.files.internal(null));

font = gen.generateFont(20);

menuItems = new String[]{
"Play"
};
}

public void update(float dt) {
handleInput();
}

public void draw() {
sb.setProjectionMatrix(Main.cam.combined);//*** This is where the null pointer starts *********

sb.begin();
font.draw(sb, "Quack", Main.WIDTH / 2, Main.HEIGHT / 2);//*** This does not work *******************
sb.end();

}

public void handleInput() {

}

public void dispose() {

}

}

主类
package com.mygdx.finis;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.mygdx.finis.states.GameStateManager;

public class Main implements ApplicationListener{

public static int WIDTH;
public static int HEIGHT;

public static OrthographicCamera cam;

private GameStateManager gsm;

public void create(){
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();

cam = new OrthographicCamera(WIDTH, HEIGHT);
cam.translate(WIDTH / 2, HEIGHT / 2);
cam.update();

gsm = new GameStateManager();
}

public void render(){
Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);

gsm.update(Gdx.graphics.getDeltaTime());
gsm.draw();//****** THIS IS WHERE THE ISSUE ENDS ******
}

public void resize(int width, int height){}
public void pause(){}
public void resume(){}
public void dispose(){}
}

最佳答案

您的SpriteBatch sb很有可能为空。您绝对确定要调用init()吗?

唯一的替代方法是Main.cam为null。

它必须是其中之一。

顺便说一句,这在我看来很奇怪。

Gdx.files.internal(null));

你为什么要这么做?

关于java - Java libGdx : FreeTypeFontGenerator is not working (Black screen),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34288648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com