One way to do this is to use scene2d tags. They are very easy to work with, and you can do what you want if you read the Scene2D user interface and Shortcuts . However, some people prefer not to use Scene2D. The following code does what you want, but this is a bit of extra work to avoid using Scene2D.
public SpriteBatch spriteBatch; private int posX = 100; private int posY = 100; private float angle = 45; private String text = "Hello, World!"; private BitmapFont font; private Matrix4 oldTransformMatrix; Matrix4 mx4Font = new Matrix4(); @Override public void show() { font = new BitmapFont(Gdx.files.internal("someFont.ttf")); oldTransformMatrix = spriteBatch.getTransformMatrix().cpy(); mx4Font.rotate(new Vector3(0, 0, 1), angle); mx4Font.trn(posX, posY, 0); } @Override public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.setTransformMatrix(mx4Font); spriteBatch.begin(); font.draw(spriteBatch, text, 0, 0); spriteBatch.end(); spriteBatch.setTransformMatrix(oldTransformMatrix); }
I hope some of them may come in handy.
source share