Label Text Stack after setFontScale Libgdx - libgdx

After scaling my label to fit into box2d environment, my label text will stack together looks like this:
It suppose to be abc123.
My codes are as below:
Label label = new Label("abc123",game.getUiSkin());
Container container = new Container<Label>(label);
container.setTransform(true);
label.setFontScale(1/GC.UNITS_PER_METER);
container.pack();
box2dStage.addActor(container);
I'm using container for label because want to apply scaling action on it. Anyone please help.

Try to remove container.pack(); method.

Related

Is there a script or binding that I can use to make a text box read only?

I need to use a text box to display the information but it needs to be read only so that the user can't edit the information in the box.
I have looked at other questions similar to this and tried their way but nothing has worked out.
In addition to the solution from #Markus Malessa in the comment above, you can also just use a label instead of a text box to accomplish the same thing. I have a custom label style set up that I can use to make the text in the label look like the text in any surrounding text boxes. Using the label instead means that the user doesn't get the disabled pointer when they mouse over it.

How can I align label of a button component

I have a button component on my scene. But when I set labelPlacement to left, it can't do that. How can I fix this?
From what I understand and have read about the labelPlacement property is that it works in conjunction with the use of an icon within the button, not to necessarily change the position of the text in relation to the button boundary.
Here is some text that documents this from the Adobe Website:
If you are using an icon with a Button instance, you can control the placement of the text label, relative to the icon, by setting the labelPlacement property using one of the constants from the ButtonLabelPlacement class (fl.controls.ButtonLabelPlacement). For more information on working with button icons, see Setting icons.
Source: http://www.adobe.com/devnet/flash/quickstart/button_component_as3.html
Additional sources: http://www.adobe.com/devnet/flash/quickstart/button_component_as3.html#articlecontentAdobe_numberedheader_6
However, a hackish way of moving the text to the left would be to add spaces to the right of the string. Currently, empty spaces at the start or end of the label are not auto trimmed. Here is an example of what I am talking about:
import fl.controls.Button;
var myButton:Button = new Button();
myButton.label = "Click me ";
addChild(myButton);
I tested the code shown above in Flash CC 2014 and the text looked like it was left aligned, when it really wasn't because of the additional spaces added to the end of label.
It is worth mentioning that I also experiemented with the textField property of the Button class to see if the autoSize or setTextFormat functionality could be used to left align the text, and those all failed.

Making dynamic text movable?

I have this DIY designer where a user can put text on a board. The problem is it cant be moved. I can do draggable movieclips but not dynamic text. Is it possible?
I'm assuming your dynamic text is going into something like a label or an Flex TextArea or TextInput or something. You should just be able to move the container itself by setting the x and y properties. TextInputs have opaque backgrounds, but it sounds like you should probably be using a Flex TextArea or something similar anyway.

AS3 : How to show image within text in same line

I would like to show some images and text in the same line. The text and image is completely dynamic. At first I thought to use htmlText property of TextField as img tag is supported. Something like this:
var tf:TextField = new TextField();
tf.htmlText = "before img <img src='img.png'> after image";
addChild(tf);
But I found that the image is showing in the next line, not in the middle of two text segments. Then after checking the manual of TextField I have found that this is the documented behavior that the image will be shown on the line following the img tag.
So what is the best way to do this? Note that the text and position of images are completely dynamic.
I understand that it is possible to split the input in a series of texts and images and then position them calculating the text and images width. In other words parse the input ourselves.
Is there any better way to do this? Or is there any library available that does this parsing?
Hail, Taskinoor.
You need use TLF.
You can follow this link that describe even more that you want.
Edit: I'm assuming you are using Flex (TextFlow).
Don't know if it is possible directly on Flash with Flex SDK4...
Maybe you'll need TLF2 (Flex SDK 4.5 Hero)

flex textflow dyniamic height

In my flex application I have scenerio like this:
parent to child
Vbox->Canvas->Sprite->Textflow
In this scenerio now I need to have dynamic height of the textflow & its parents. Here the root parent is the itemrenderer of the datagrid I have.
I need the heights of rows to be adjust according the content in it.
Right now I am importing the xml to textflow, then getting the number of lines, text height. Then removing the textflow & adding it again with the measured height according to the number of lines & text height.
How can I achieve it without removing & adding it again, coz it is taking much time in updating?
Thanks in advance.
Right might be a little late to answer this but someone else may benefit.
On the canvas or display object housing the TextFlow and sprite add a creationComplete functon.
I don't know if this step is necessary, but it works for me. Add a label with the text thats going to go into TextFlow (with the same font and fontSize), add a creation complete listener to that as well.
Get the height and width from the newly created label e.target.width e.target.height (in the function listening to the creation of label). Set the displayObjects (in the above case Canvas) height and width to these values, then proceed to add the sprite and textflow.
Note: this was a lazy way for me, label uses measureText which would be a more efficent way of doing this.