Java LibGDX Flip String Vertical

时间:2016-08-31 16:27:43

标签: java android libgdx

我的代码:

SpriteBatch batch = new SpriteBatch();
BitmapFont font = new BitmapFont();
String string = "100";
batch.begin()
font.draw(batch, string, 0, 0);
batch.end();

我试过了:

font.draw(batch, new StringBuilder(string).reverse(), 0, 0);

但结果" 001"。我不想横向翻转,我想翻转垂直例如:

100

3 个答案:

答案 0 :(得分:1)

Use new BitmapFont(true) to generate an upside-down font.

Or you can flip your font back and forth with font.setScale(1, -1).

答案 1 :(得分:0)

Seems like what you are trying is can't be achieved with text but can be achieved with image because the vertical flip of your text is not an actual text in real world.

So what you can do is create an image and you can simply scale its height by -1 to achieve the desired effect.

Hope this helps, Try something and come up with some efforts to get better response.

答案 2 :(得分:0)

You can render the text to an off-screen target, and then render that target texture with flipped coordinates. You can use a FrameBuffer for this.

Another alternative is to flip the camera itself, by setting your SpriteBatch projection matrix before calling batch.begin()

Matrix4 matrix = new Matrix4();
...
batch.setProjectionMatrix(matrix.set(camera.combined).scl(1, -1, 1));
batch.begin();
font.draw(batch, string, 0, 0);
batch.end();