I'm currently making a Minecraft mod, and I need to render text so that it aligns with the right side of the screen. I know the way to do this in CSS is by setting the right property to 0, or however many pixels you need the text off the right side of the screen.
However, I can't seem to find anything relating to this in Java. Minecraft comes with some default functions you can use to render text. I am using mc.fontRendererObj.drawString(<text>, <x>, <y>, <color>) to draw text. You can also use the variable GlStateManager to modify the text using it's variables and functions.
I'm fairly certain that with these I can achieve what I'm trying to do, but I can't find a way to do it. Does anyone know how I can do this?
Using the drawString method, you need to calculate <x> and <y> such that the end of the text aligns with the right side of the area in which you are drawing the text. So you need to obtain the width of that area as well as the width of the text you are writing. Then you can calculate <x>. Of-course the <y> does not affect right-alignment. In pure java there are methods for obtaining the width and for the length of the text, both in pixels.
Related
I have this picture:
It contains circles inside columns. I want to get:
The height of each circle relative to its column (the distance
between the column bottom and the circle)
The height of the whole column
Classify every column so I can use the data from every column
differently according to its rank from left to right using java in
android studio.
I know I'm asking a lot but is that possible?! and if it is how can I do that?
Thanks in advance
Yes it must be possible. I have used this concept in Python using OpenCV but not in Java. The idea is to recognise your target inside an image by image recognition and then calculating pixel ratios. Use the same logic and code in Java as OpenCV is there for Java too.
Helper link below,
https://www.pyimagesearch.com/2016/03/28/measuring-size-of-objects-in-an-image-with-opencv/
If you have already started any other implementation and obtaining errors, post it too.
I want to draw Strings in my Libgdx game but i cant use BitMap Fonts because the scale of my game is to smal to use them.
It sounds like you mean the scale of your viewport is too small to show fonts correctly. There are two solutions. The first is better for legibility while the second is quick and dirty.
One is to use a second viewport for the UI that has an appropriate scale for text. You would first call gameViewport.apply(), draw the game, and end the batch. Then use uiViewport.apply() and then draw the UI. The downside with this method would be if you want to draw text that aligns with moving objects in the game, you would have to use the two viewports to convert coordinates. Otherwise, this is the ideal method to get a crisp looking UI. Ideally you would use a ScreenViewport and select a font size at runtime based on the screen dimensions, either by shipping your game with multiple versions of the font at different scales, or by using FreeTypeFontGenerator.
The second method is to scale down all your text. First call bitmapFont.setUseIntegerPositions(false) do it won't round off positions to integers. Then call bitmapFont.setScale() with however much you want to shrink it to fit in your game viewport.
There is a gdx-freetype project:
https://www.badlogicgames.com/wordpress/?p=2300
and it uses TrueType fonts as source to generate bitmap font on the fly.
Not sure how stable this is - didn't use it.
I'm trying to build a text editing app that allows the user to edit text using different fonts, colors, sizes, rotations, etc. I'm working on a feature that is supposed to curve the text but I've got no clue how to do it. I found this StackOverflow post HERE and searching through the comments, I found this post HERE but for what I'm trying to achieve, that is how I want it to end up. What I want it to do is start as a normal line of text and then based on the value of a seekbar I want it to curve, until it reaches the MAX value at which point it's in a circle (as seen in the second link). If you can help me figure out how to do this I would really appreciate it. I figure it's going to use path.addArc or something like that but I'm not sure.
Thank you
PS
I'll post the images below just in case you don't want to go look at the links
You can draw your circle text in your custom view, use canvas function drawTextOnPath(String text,Path path, float hOffset, float vOffset,Paint paint), and then construct the path by yourself requirement.
So I have a custom class called RoundRectText that draws text inside a RoundRect created from Path.addRoundRect(). What I'd like to do is prevent the posibility of this happening:
I want to prevent the text from running outside the rectangle. Is there any way I can cut off the drawing at a certain point?
The best solution I have come up with is looping through the String and using Paint.measureText() to stop drawing the rest of the String if it surpasses the width but I'd like to know if there is another/better way to do this.
I have also tried using Canvas.clipRect() but this gets rid of other things that I draw and still draws the text going out of the bounds
I am working on a game using LibGDX, and right now, I am working on the menu screen. What I want to do, is have a small image, set a bounding box, and expand however large I need it. What I think would be optimal, would be to set 2 rectangles. One for width and one for height. If it needs to get bigger or smaller, it would take that rectangle, and duplicate it beside, or beneath the current one, depending if it is for the width or height. I believe there is a builtin class for this, but I cannot seem to find it.
You might want to take a look at NinePatch if I'm not misunderstanding your question. Link here: https://github.com/libgdx/libgdx/wiki/Ninepatches