Single line text alignment doesn't seem to work.

Hi,

I want to align my score number to right side of my HUD so it will be nicer. So I’ve googled and read that:

Currently, there is no way to align text upon creation. It is recommended you create the text, then set the reference point using object:setReferencePoint(), and adjust the x and y coordinates accordingly.

So I tried this:

scoreTextField = display.newText("0" ,display.contentWidth / 2 - 105, 5,"Tahoma", 16) scoreTextField:setReferencePoint(display.TopRightReferencePoint) scoreTextField.x, scoreTextField.y = display.contentWidth / 2 - 105, 6 HUDcontiner:insert(scoreTextField)

but alignment doesn’t change.

What am I missing here? I change reference point and re assigned the position.

Thanks.

I wouldn’t rely on setting the Reference Point. You could use the width of the text to adjust the text’s position instead.

[LUA]

scoreTextField.x, scoreTextField.y = display.contentWidth / 2 - 105 - scoreTextField.width, 6

[/LUA]

The only annoying thing is, that you have to reset the x-position of the text every time you change the text, but that’s a minor problem I think.

[LUA]

scoreTextField.x = display.contentWidth / 2 - 105 - scoreTextField.width

[/LUA]

I wouldn’t rely on setting the Reference Point. You could use the width of the text to adjust the text’s position instead.

[LUA]

scoreTextField.x, scoreTextField.y = display.contentWidth / 2 - 105 - scoreTextField.width, 6

[/LUA]

The only annoying thing is, that you have to reset the x-position of the text every time you change the text, but that’s a minor problem I think.

[LUA]

scoreTextField.x = display.contentWidth / 2 - 105 - scoreTextField.width

[/LUA]