На данный момент я пишу игру на LibGDX. И у меня есть вот такой код:
@Override
public void render(SpriteBatch batch) {
batch.begin();
Draw.draw();
MainScreen.player.draw();
TextManager.displayMessage("FPS: "+ Gdx.graphics.getFramesPerSecond(), true, false, false, false);
PlayerControl.update();
CamControl.update();
UI.drawCurrentBlock();
batch.end();
}
Проблема в том, что надпись-счетчик fps, который реализуется при помощи TextManager, не "прикреплен" к экрану. Он попросту стоит на месте на поле игры. Мне же нужно, чтобы он следовал за игроком/камерой. Помогите реализовать данный аспект.
package aof.loaders;
import aof.screens.MainScreen;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
public class TextManager {
static BitmapFont font;
static float width, height;
public static void initialize(float width,float height){
font = new BitmapFont(Gdx.files.internal("fonts/font.fnt"));
TextManager.width = width;
TextManager.height = height;
font.getData().scaleX = MainScreen.aspectRatio * 1.5f;
font.getData().scaleY = 1;
Log.info(font.getData().scaleY);
}
public static void displayMessage(String text, float x, float y){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font, text);
font.draw(MainScreen.batch, glyphLayout, x, y);
}
public static void displayMessage(String text, boolean left, boolean right, boolean top, boolean bottom){
float x = (float) MainScreen.WIDTH/2, y = (float) MainScreen.HEIGHT/2;
if(left) x = 0;
if(bottom) y = 20;
if(right) x = MainScreen.WIDTH-50;
if(top) y = MainScreen.HEIGHT-20;
displayMessage(text, x, y);
}
public static void dispose() {
font.dispose();
}
}
Код TextManager.
Пробовал решить данную проблему посредством прикрепления надписи непосредственно к координатам камеры. Однако, в этом случае, текст и/или картинка подергивается. То есть, не статичны.