Libgdx how to get the total width of a text? (BitmapFont)
-
How to get the total width of a BitmapFont text? font.draw(batch, text ,Gdx.graphics.getWidth() / 2 - /* text width */ /2,450);
-
Answer:
Use a https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/GlyphLayout.html to calculate the width of some string using a particular font: GlyphLayout layout = new GlyphLayout(font, text); float textWidth = layout.width; Don't put this in the render method, though. It is a good idea to calculate and store this value once in create or show and then just use the value in your render.
Mr Zombie Pigman at Stack Overflow Visit the source
Related Q & A:
- How To Get All Components Based On A Schema And From A Particular Publication?Best solution by Tridion
- How to get the group ID of a contact in android?Best solution by Stack Overflow
- How to get all the content of a page?Best solution by Stack Overflow
- How to get mobile scrollbar width?Best solution by Stack Overflow
- How to get actual return type of a generic static method in Java?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.