我无法显示文本(它们应该显示为滚动损坏数字)。如果我插入一个字符串文字作为 .draw 的参数,它就可以工作。像这样:
damage.fontObject.draw(game.batch,"testtest", x, y);
滚动也有效(在 SpriteBatch 绘图内容之外的另一个函数内)。
出于某种原因,它只是不接受我存储在对象内部的变量。显然我错过了一些东西。
在渲染()
game.batch.begin(); //render begin
renderDamageText();
game.batch.end(); //render end
在 renderDamageText()
public void renderDamageText(){
for(int i = 0; i < damageText.size; i++){
GameText damage = damageText.get(i);
String showThis = damage.getText();
float x =damage.x;
float y =damage.y;
damage.fontObject.draw(game.batch,showThis, x, y);
}
}
游戏文本类
public class GameText {
public MyGdxGame game;
public String text;
public float x;
public float y;
public BitmapFont fontObject;
public float alpha = 1;
public float width;
public float height;
public GameText(String text, MyGdxGame game, BitmapFont font, float x, float y){
this.x=x;
this.y = y;
fontObject = font;
this.game = game;
this.text = text;
setText(game, text);
}
public String getText(){
return text;
}
public void setText(MyGdxGame game, String text){
game.textLayout.setText(fontObject,text);
width= game.textLayout.width;
height = game.textLayout.height;
x-=width/2;
y-=height/2;
}
}
当前的代码是在制品和混乱,只是想让它工作然后清理它。