我似乎無法弄清楚如何正確旋轉一個Bitmap字體。我認爲你修改了SpriteBatch的轉換矩陣。然而,試圖旋轉旋轉文本週圍的某個點,我不知道如何相對於文本本身旋轉它。繪製一個BitmapFont在libgdx中旋轉
6
A
回答
4
你可以試試下面的代碼:
Matrix4 mx4Font = new Matrix4();
BitmapFont font;
SpriteBatch spriteFont;
font = new BitmapFont(Gdx.files.internal("data/font/agencyFB.fnt"), Gdx.files.internal("data/font/agencyFB.png"), true); //must be set true to be flipped
mx4Font.setToRotation(new Vector3(200, 200, 0), 180);
spriteFont.setTransformMatrix(mx4Font);
spriteFont.begin();
font.setColor(1.0f, 1.0f, 1.0f, 1.0f);
font.draw(spriteFont, "The quick brown fox jumped over the lazy dog", 100, 110);
spriteFont.end();
5
您可以創建一個字形到一個精靈。這樣,你可以將你的文本操作爲精靈。
示例代碼:
請注意,這將返回單個字形的Sprite。 (如字符「A」轉化成一個精靈。)
/** Creates a sprite from a glyph.
*
* @param ch
* @return Sprite
*/
public Sprite getGlyphSprite (char ch) {
Glyph glyph = Globals.g.font.getData().getGlyph(ch);
Sprite s = new Sprite(Globals.g.font.getRegion().getTexture(),
glyph.srcX,glyph.srcY,glyph.width, glyph.height);
s.flip(false, true);
s.setOrigin(glyph.width/2, glyph.height/2);
return s;
}
0
我只想補充..我想你有一些圖冊內的字體的基本圖像..所以你需要添加TextureRegion原件SOT gliph SRC因爲它只是相對於給定的紋理區域所以
BitmapFont font = ...
BitmapFont.Glyph glyph = font.getData().getGlyph(ch);
int srcX = glyph.srcX + font.getRegion().getRegionX();
int srcY = glyph.srcY+ font.getRegion().getRegionY();
Sprite s = new Sprite(font.getRegion().getTexture(), srcX,srcY,glyph.width, glyph.height);
0
Lunatikul的第一個答案沒有在我的2D情況下工作。它將我的文本只切成半個字母。我是全成下列要求:
batch.begin();
batch.setTransformMatrix(new Matrix4().setToRotation(0,0,1,<insert angle here>));
font.draw(batch, "Hallo Welt", 100, 100);
batch.end();
相關問題
- 1. 如何在LibGDX中繪製BitmapFont?
- 2. 如何讓我的LibGDX BitmapFont繪製?
- 3. LibGDX:是否可以繪製一個BitmapFont並更新它?
- 4. Strech在LibGdx BitmapFont
- 5. Libgdx如何翻轉BitmapFont?
- 6. Libgdx如何動畫一個BitmapFont?
- 7. 用BitmapFont繪製字符串
- 8. 在libGdx中旋轉線條
- 9. (Libgdx)BitmapFont顏色和Opengl 2
- 10. libgdx添加分數BitmapFont
- 11. LibGDX + Box2D旋轉
- 12. libgdx particleEffect旋轉
- 13. Libgdx旋轉ModelInstance
- 14. 如何在OpenCV中繪製一個旋轉的空中飛人?
- 15. LibGDX移動一個旋轉的相機
- 16. 在LibGDX中繪製文本
- 17. 在SkiaSharp中繪製旋轉文字
- 18. 在MATLAB中繪製*旋轉*拋物線
- 19. 文字旋轉libgdx
- 20. 繪製一個單精靈Pixmap - LibGDX
- 21. libgdx:製作十字形狀旋轉
- 22. 繪製旋轉的矩形
- 23. 繪製旋轉三角形
- 24. iPhone:繪製旋轉文字?
- 25. 鏈接3D旋轉繪製
- 26. iPhone:旋轉繪圖而不旋轉繪製它的視圖
- 27. 在Libgdx中定位和旋轉動畫
- 28. 在Libgdx中設置相機旋轉
- 29. 在遊戲中旋轉物體LibGDX
- 30. 在libgdx中使用ShapeRenderer旋轉矩形
你應該做setToRotation – chairbender 2014-07-18 04:20:39
我沒有工作的時候是什麼意思載體闡述,我在這裏失蹤? – 2015-05-15 10:28:56