Why LandscapeLeft or LandscapeRight is not aligning to the middle?

Thanks for helping me :slight_smile:
[lua]display.setStatusBar( display.HiddenStatusBar )

local maindisplay = display.newGroup()

local background = display.newImage( “world.jpg” )
maindisplay:insert( background, true )
background:setReferencePoint(display.CenterReferencePoint)
background.x = 160; background.y = 240
maindisplay:setReferencePoint(display.CenterReferencePoint)

local myText = display.newText( “From Sam!”, 0, 0, native.systemFont, 40 )
myText:setTextColor( 255,110,110 )
maindisplay:insert( myText, true )
print ( "display.contentWidth: " … display.contentWidth )
print ( "display.contentHeight: " … display.contentHeight )
print ( "myText.width: " … myText.width )

myText:setReferencePoint(display.CenterLeftReferencePoint)
myText.x = (display.contentWidth / 2)- (myText.width / 2)
myText.y = display.contentHeight / 2

– Use accelerometer to rotate display automatically
local function onOrientationChange( event )

– Adapt text layout to current orientation
local direction = event.type

print ( "direction: " … direction )
print ( "display.contentWidth: " … display.contentWidth )
print ( "display.contentHeight: " … display.contentHeight )
print ( "myText.width: " … myText.width )

if ( direction == “landscapeLeft” or direction == “landscapeRight” ) then
myText:setReferencePoint(display.CenterLeftReferencePoint)
myText.x = (display.contentWidth / 2)- (myText.width / 2)
myText.y = display.contentHeight / 2
elseif ( direction == “portrait” or direction == “portraitUpsideDown” ) then
myText:setReferencePoint(display.CenterLeftReferencePoint)
myText.x = (display.contentWidth / 2) - (myText.width / 2)
myText.y = display.contentHeight / 2
end
– Rotate clock so it remains upright
local newAngle = maindisplay.rotation - event.delta
transition.to( maindisplay, { time=50, rotation=newAngle } )

end

Runtime:addEventListener( “orientation”, onOrientationChange )[/lua] [import]uid: 99380 topic_id: 19947 reply_id: 319947[/import]

Please post your code in lua tags. < lua > and < / lua > without the spaces. (I edited it.)

Change line 39 to this;
[lua]myText.x = display.contentHeight / 2 - myText.width / 2[/lua]

That will fix it I believe :slight_smile:

Peach [import]uid: 52491 topic_id: 19947 reply_id: 77710[/import]