Unable to properly position a DisplayObject when orientation changes.

Hi,

I am facing a problem that when trying to center a DisplayObject after device rotation.

The objects starts out in the Center of the screen, but after I rotate the Device to landscape mode, the x and y of the object still seemed to be referencing the previous orientation, and the object doesn’t center in landscape mode.

Rotating it back to Portrait or PortraitUpsideDown mode and the object centers.

Here’s my code:
[lua]local redMarble = display.newImage(“redmarble.png”)

– setup their starting positions
function placeMarbles()
local screenWidth = display.contentWidth
local screenHeight = display.contentHeight
transition.to(redMarble, {timer=1000, x=(screenWidth/2), y=screenHeight/2})
end

function onOrientationChange( event )
print ("Orientation: ", event.type)
print ("ScreenWidth: ", display.contentWidth)
print ("ScreenHeight: ", display.contentHeight)
placeMarbles()
end

– Setup Event Listener
Runtime:addEventListener(“orientation”, onOrientationChange)
placeMarbles()[/lua]

Thank you. [import]uid: 190205 topic_id: 32909 reply_id: 332909[/import]

You need to provide more information about what you’re doing.

  1. What device are you seeing this on (mac sim, win sim, iPhone, android, etc.)?
  2. Do you have an Orientation table in your build.settings file to allow auto-rotation?

This is a known bug in the simulator if you rotate the skin and you don’t specify that the new orientation is supported in the build.setttings file. The bug is the contentWidth and contentHeight is swapped when it shouldn’t. [import]uid: 7559 topic_id: 32909 reply_id: 130880[/import]

Thanks Tom.

The build.settings file did the trick. Didn’t know about this bug earlier.

I am just starting out learning Corona and encountering this on the mac sim.

Thanks again. [import]uid: 190205 topic_id: 32909 reply_id: 130885[/import]

You need to provide more information about what you’re doing.

  1. What device are you seeing this on (mac sim, win sim, iPhone, android, etc.)?
  2. Do you have an Orientation table in your build.settings file to allow auto-rotation?

This is a known bug in the simulator if you rotate the skin and you don’t specify that the new orientation is supported in the build.setttings file. The bug is the contentWidth and contentHeight is swapped when it shouldn’t. [import]uid: 7559 topic_id: 32909 reply_id: 130880[/import]

Thanks Tom.

The build.settings file did the trick. Didn’t know about this bug earlier.

I am just starting out learning Corona and encountering this on the mac sim.

Thanks again. [import]uid: 190205 topic_id: 32909 reply_id: 130885[/import]