Yet another crazy align left question.

I’ve seen link after link on these forums about how to align display.newText using setReferencePoint…but the bottom line is that the two just don’t seem to work together.

local myText = display.newText ( "", 100, 200) myText.text = "This is an alignment check.:" myText.align = "left" myText:setReferencePoint(display.BottomLeftReferencePoint)

is the same as…

local myText = display.newText ( "", 100, 200) myText.text = "This is an alignment check.:"

…and so on. Really haven’t the slightest idea how to print text that isn’t center-aligned. I figure I must be missing something really obvious…

[import]uid: 41884 topic_id: 12818 reply_id: 312818[/import]

I can’t remember, but try setting myText.xOrigin to something like 20. I believe that’ll put the left size @ 20 px…

If not, for some reason I remember having done the math – something like

myText.x = 100 - myText.width/2 

However, I don’t bother with it much anymore cause you can just get crawlspaceLib and just use newParagraph’s align=“center”.

Go here, get this -->
http://www.crawlspacegames.com/crawl-space-corona-sdk-library/
[import]uid: 13859 topic_id: 12818 reply_id: 47013[/import]

Kind of insane to have to start figuring out how to integrate external libraries after not having even 5 lines of working code, but I’ll check it out.

FWIW, I tried myText.xOrigin = 20

a) It doesn’t work
b) It actually has an interesting bug / side effect.

local myText = display.newText( "",100,200) myText.text = "This is an alignment check." myText.xOrigin = 20

The above does nothing, even if you add in the setReferencePoint command.

However! If you:
a) Delete the xOrigin statement
b) Follow up the code with this:

local myText2 = display.newText( "",100,200) myText2.text = "This is an alignment check." myText2.xOrigin = 20

…believe it or not, myText becomes well aligned but myText2 stays unaligned. Somehow, the myText2.xOrigin command is aligning the first one. (I even tried completely changing the name from myText2 - it still does it.) [import]uid: 41884 topic_id: 12818 reply_id: 47016[/import]

Your above examples are explainable. By default you are going to get a center alignment.

When you created the newText object above at 100,200 you shifted it over on the x-axis 100 pts, so you see that when you alter the xOrigin you really start moving it around. myText and myText2 aren’t doing anything to influence the other. When you removed the xOrigin setting from myText you are simply going back to center alignment and starting at 100.

It’s all a matter of the order, probably you are after something like this:

local myText = display.newText( "",0,200)  
myText.text = "This is an alignment check."  
myText:setReferencePoint(display.CenterLeftReferencePoint);  
myText.x = 20;  

And read this from the API docs for details: object:setReferencePoint( )
Hope that helps and makes sense,

Croisened
[import]uid: 48203 topic_id: 12818 reply_id: 47023[/import]

Ah, I get it now. Had to retype my entire post, but yeah. So the gist is that if you don’t set object.x, ReferencePoint doesn’t update the draw cycle.

Nonetheless, I think I’ll take a look at that external library.

Now I only need to figure out how to load external tables…:slight_smile: [import]uid: 41884 topic_id: 12818 reply_id: 47068[/import]

I take that back. I *thought* I understood. But now it’s the same basic problem.

detailScreenOwner = display.newText("Playername",0,0)  
detailScreenOwner:setReferencePoint(display.BottomLeftReferencePoint)  
detailScreenOwner.x = math.floor(display.contentWidth\*0.2)  

Using this code the text is still center-justified. (An easy way to prove it? Use display.contentWidth*0.5) However, I do know the line is being used as it is clearly using “bottom” instead of “center” on the Y axis.

Is there maybe a way I can display the reference point in the simulator? I’m wondering if being in a group is somehow preventing me from setting left alignment… [import]uid: 41884 topic_id: 12818 reply_id: 48091[/import]