Text assignment clears reference point

5 replies [Last post]
Rozek
User offline. Last seen 1 year 3 weeks ago. Offline
Joined: 25 Dec 2009

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 ;-)

Kind regards,

Andreas Rozek

Replies

Rozek
User offline. Last seen 1 year 3 weeks ago. Offline
Joined: 25 Dec 2009

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

carlos m. icaza's picture
carlos m. icaza
User offline. Last seen 9 hours 49 min ago. Offline
Ansca Staff
Joined: 22 Jun 2009

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

Rozek
User offline. Last seen 1 year 3 weeks ago. Offline
Joined: 25 Dec 2009

Carlos,

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

Andreas

seanh
User offline. Last seen 1 hour 37 min ago. Offline
Ansca Staff
Joined: 3 Jun 2009

(Logged as bug #140)

walter
User offline. Last seen 5 hours 6 min ago. Offline
Ansca Staff
Joined: 22 Jun 2009

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

1
2
3
Line2.text = "this is just another text"; -- clears the reference point!
Line2:setReferencePoint(display.CenterLeftReferencePoint);
Line2.x = 160;

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.

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.