我试图在 libGDX 中编写简单的游戏,但这个问题阻止了创建该游戏的整个过程。这里有两节课。
public class Question {
private static float getFontX() {
return Assets.font.getBounds(Database.getText()).width / 2;
}
private static float getFontY() {
return Assets.font.getBounds(Database.getText()).height / 2;
}
public static void draw(SpriteBatch batch) {
Assets.font.draw(batch, Database.getText(),
TOFMain.SCREEN_WIDTH / 2 - getFontX(),
getFontY() + 250 + TOFMain.SCREEN_HEIGHT / 2);
//drawing some text from database on screen in the middle of screen;
}
第二类是数据库,它包含问题
public class Database {
private static String questions[] = new String[2];
{
questions[0] = "Some question1";
questions[1] = "Some question2";
}
static public String getText() {
return questions[0];
}
}
里面有问题
return questions[0]
因为如果我在那里写例如
return "This will work";
一切都好。