Show text on center of screen

How to show text on center of screen ?

I was trying something like this:

1
2
3
4
5
6
7
8
9
local centarX = display.contentWidth  / 2
local centarY = display.contentHeight / 2
 
local myText = display.newText( "Hello, World", 0, 0, "Helvetica", 40 )
myText.isVisible = false
 
myText.x = centarX - (myText.contentWidth  / 2)
myText.y = centarY - (myText.contentHeight / 2)
myText.isVisible = true

maybe like this?

1
2
3
4
5
6
7
8
local centarX = display.contentWidth / 2;
local centarY = display.contentHeight / 2;
 
local myText = display.newText( "Hello, World", 0, 0, "Helvetica", 40 )
myText.isVisible = false
myText.x = centarX;
myText.y = centarY;
myText.isVisible = true

Or this:

1
2
3
4
5
6
7
local centarX = display.contentWidth  / 2
local centarY = display.contentHeight / 2
 
local myText = display.newText( "Hello, World", 0, 0, "Helvetica", 40 )
myText:setReferencePoint(display.CenterReferencePoint)
myText.x = centarX
myText.y = centarY

Thanks dingo & robmiracle

views:1371 update:2011/11/25 8:45:21
corona forums © 2003-2011