Center positioning newText

I am sorry if this is a bother, but I cannot figure out how to get my text object centered correctly!
Here is what I am doing:

--This acts as a backdrop for the "bubbleText" below.  
speechBubble = display.newImageRect("talk-bubble.png", 180, 76)  
speechBubble:setReferencePoint(display.CenterReferencePoint)  
speechBubble.alpha = 0  
GUIGroup:insert(speechBubble)  
  
--This is the actual text object  
bubbleText = display.newText(getSpeechInfo( thisCharacterID ).text, 0, 0, speechBubble.width, speechBubble.height, "Chantelli Antiqua", 12 )  
bubbleText:setReferencePoint(display.CenterReferencePoint)  
bubbleText.x = thisBubbleInfo.x + (speechBubble.contentWidth \* 0.5)  
bubbleText.y = thisBubbleInfo.y + (speechBubble.contentHeight \* 0.5)  
  

So the issue I am seeing is that the text object seems to be positioning using the top left corner, with the above code, I was trying to force it to be centered, but the top left corner of the text object is then positioned in the center of the backdrop image… Any ideas would be great [import]uid: 19620 topic_id: 28253 reply_id: 328253[/import]

Sorry can’t edit original post, but the speechBubble gets its x and y placement dynamically, its a story book.

[code]

speechBubble.x = thisBubbleInfo.x
speechBubble.y = thisBubbleInfo.y

[/code] [import]uid: 19620 topic_id: 28253 reply_id: 114157[/import]

Could you upload something or provide plug and play please?

Alternatively, is it possible that the string of text is simply shorter than the width of the bubble? If it is it could very well appear it isn’t registering the center reference point when it is simply because the text is as wide as the width you specified and not the width of the actual text you see on the screen, if that makes sense?

Peach [import]uid: 52491 topic_id: 28253 reply_id: 114195[/import]

Ok here is some code that shows my problem, its probly something really easy but I am not sure what I am doing wrong.

So go ahead and just put the following code in a ‘main.lua’ and also use a config that is setup 320x480

  
local thisBackdrop = display.newRect( 0, 0, 300, 100 )  
thisBackdrop.x = 165  
thisBackdrop.y = 150  
  
local thisText = display.newText("Here is a long string of text, lalallalala! And im going to keep on typing right now to see if it wraps", 0, 0, 300, 100, system.nativefont, 12 )  
thisText:setTextColor(0,0,0)  
thisText:setReferencePoint(display.centerReferencePoint)  
thisText.x = thisBackdrop.x  
thisText.y = thisBackdrop.y  
  

So as you can see, I am telling the text to be the same x and y as the backdrop, but it instead is snugged in the top left corner of the backdrop, what I am trying to accomplish is to get my text centered both vertically and horizontally over the backdrop area. [import]uid: 19620 topic_id: 28253 reply_id: 114216[/import]

Oh I seem to have figured it out… In the creation of my text object, if I just put the height for the multiline property to 0, then it seems to position correctly! Before I was telling it that I wanted it to be 100 high, for whatever reason that screws things up? [import]uid: 19620 topic_id: 28253 reply_id: 114220[/import]

It’s because of the height of the text box. You could also set it to 50 for your two lines of text and the affect would be similar. If the height is stuck to 100 then the text will still appear at the top until it is long enough, then when it’s 100 pixels the box will let you scroll.

Also, as a side note, I see you said system.nativefont - that should be;
[lua]native.systemFont[/lua]

Peach :wink: [import]uid: 52491 topic_id: 28253 reply_id: 114276[/import]