Text assignment clears reference point

Hello!

That’s strange: if you have a text display object with a non-standard reference point, this reference point is forgotten as soon as one assigns a new text to that object. Here is some code to test:

Line1 = display.newText("this is just some text", 0,0, nil, 14);
Line1:setReferencePoint(display.CenterLeftReferencePoint);
 Line1.x = 20;
 Line1.y = 40;
Line1:setTextColor(222,222,222);

Line2 = display.newText("(n/a)", 0,0, nil, 14);
Line2:setReferencePoint(display.CenterLeftReferencePoint);
 Line2.x = 20;
 Line2.y = 60;
Line2:setTextColor(222,222,222);

Line2.text = "this is just another text"; -- clears the reference point!

It took some time to find out why my layout got messed up from time to time - but now I know the reason and have a workaround :wink:

Kind regards,

Andreas Rozek [import]uid: 4331 topic_id: 447 reply_id: 300447[/import]

oops,

it’s even worse: trying to assign a new text to an existing text object seems to destroy it internally, e.g. trying to get its “width” yields a nonsense value (in my case -2147483648)

I’m now trying to remove the old object and create a new one…

Kind regards,

Andreas Rozek [import]uid: 4331 topic_id: 447 reply_id: 861[/import]

Looks like a bug. We will add it to our bugbase.

Thanks!

BTW: Showed the new Hello World you did to the entire staff. They liked it.

Carlos [import]uid: 24 topic_id: 447 reply_id: 862[/import]

Carlos,

thanks - for everything (especially the fact, that I can now develop iPhone/iPad applications with Lua - that’s great!)

Andreas [import]uid: 4331 topic_id: 447 reply_id: 863[/import]

(Logged as bug #140) [import]uid: 3 topic_id: 447 reply_id: 2046[/import]

A workaround exists if you manually set the reference point and set the x-position *after* changing the text:

[lua]Line2.text = “this is just another text”; – clears the reference point!
Line2:setReferencePoint(display.CenterLeftReferencePoint);
Line2.x = 160;[/lua]

In our current design, reference points are statically positioned relative to the object’s local origin. When the text changes, the width and height of the text object change, so the reference point is no longer along the left boundary of the object like it was before. The workaround I’m suggesting lets you reset the reference point position and then set the x-position using that reference point.

That said, we understand it’s more convenient to make the reference point alignment dynamic. We’ll use this bug (140) to track this as a feature request. [import]uid: 26 topic_id: 447 reply_id: 5687[/import]