Centre Text on a screen coordinate

HI,
Can anyone suggest the best way of display text so that it is centred on a certain point on the screen given by the coordinates x,y.

The text to be displayed will vary and be stored in a variable.

Thanks in advance for any help

Richard

I use a global variable like this:

--Load Global variables
screenCenterX = display.viewableContentWidth / 2
screenCenterY = display.viewableContentHeight /2

Then I use it like this:

local myText = display.newText("TextHere", 0, 0, sysFont, 26)
myText.x = screenCenterX; myText.y = screenCenterY

HI,

Surely this centres it on the screen, I need to centre the text based on a particular point eg 300,200.

Also the text being displayed is in a variable and can change when it is being updated, bu I need it to remain centred.

Thanks

That will keep it centered but if you give it 300,200, when your app runs on different devices, how will that effect the display? I always us the above then use a factor of it.

Example:

myTxt.x = screenCenterX * .2 ; myTxt.y = screenCenterY * 1.5

Hi Herlyrg,

If you want it centered at 300, 200
the default is centered (mid point of text vertically and horozontally) the following url may help.
http://developer.anscamobile.com/reference/index/objectsetreferencepoint

-- Center Justified text, for variable length text
-- object:setReferencePoint( referencePoint )
-- display.TopCenterReferencePoint
local mtitle1 = "This is the Main Title"
local title1 = display.newText(mtitle1, 290, 70, nill,18)
title1:setTextColor(0,255,0)
title1:setReferencePoint(display.CenterReferencePoint)
title1.x = 300; title1.y = 200

views:1642 update:2011/11/2 21:34:51
corona forums © 2003-2011