Is this a bug or a feature?

So, I am still evaluating Corona SDK and things are a little weird at the moment.

Here is a simple project:

http://dl.dropbox.com/u/29886031/OrientationMadness.zip

With the commented out section of code, notice how changing the orientation of the simulator does indeed cause a new background to be loaded in.

Now, uncomment the section at the bottom of main.lua.

Notice how everything is now messed up.

Is it a bug or something I am not doing right?
[import]uid: 59054 topic_id: 10292 reply_id: 310292[/import]

it is a feature try this code,

[lua]display.setStatusBar(display.HiddenStatusBar)

local displayGroup = display.newGroup()

local background = display.newImageRect(“portrait.png”, 320, 480)

displayGroup:insert(background)

background.x = display.contentWidth / 2
background.y = display.contentHeight / 2

local circle1 = display.newCircle(50, 50, 30)
circle1.x = 50
circle1.y = 50
circle1:setFillColor(0, 255, 255)

displayGroup:insert(circle1)

local circle2 = display.newCircle(50, 50, 30)
circle2.x = display.contentWidth - 50
circle2.y = 50
circle2:setFillColor(255, 0, 255)

displayGroup:insert(circle2)

local circle3 = display.newCircle(50, displayGroup.height - 50, 30)

circle3:setFillColor(255, 255, 0)

displayGroup:insert(circle3)

local circle4 = display.newCircle(displayGroup.width - 50, displayGroup.height - 50, 30)

circle4:setFillColor(0, 0, 0)

displayGroup:insert(circle4)
Runtime:addEventListener(“orientation”, function(event)

print("Orientation changed to: " … event.type)
print("event.delta = " … event.delta)

if event.type == “portrait” then
background:removeSelf()

background = display.newImageRect(“portrait.png”, 320, 480)

displayGroup:insert(background)

background:toBack()
elseif event.type == “portraitUpsideDown” then
background:removeSelf()

background = display.newImageRect(“portraitUpsideDown.png”, 320, 480)

displayGroup:insert(background)

background:toBack()
elseif event.type == “landscapeRight” then
background:removeSelf()

background = display.newImageRect(“landscapeRight.png”, 480, 320)

displayGroup:insert(background)

background:toBack()
elseif event.type == “landscapeLeft” then

background:removeSelf()

background = display.newImageRect(“landscapeLeft.png”, 480, 320)

displayGroup:insert(background)

background:toBack()
end

circle1:removeSelf()
circle2:removeSelf()
circle3:removeSelf()
circle4:removeSelf()

circle1 = display.newCircle(0, 0, 30)
circle1.x = 50
circle1.y = 50
circle1:setFillColor(0, 255, 255)

displayGroup:insert(circle1)

circle2 = display.newCircle(0, 0, 30)
circle2.x = display.contentWidth - 50
circle2.y = 50
circle2:setFillColor(255, 0, 255)

displayGroup:insert(circle2)

circle3 = display.newCircle(0, 0, 30)
circle3.x = 50
circle3.y = display.contentHeight - 50
circle3:setFillColor(255, 255, 0)

displayGroup:insert(circle3)

circle4 = display.newCircle(0, 0, 30)
circle4.x = display.contentWidth - 50
circle4.y = display.contentHeight - 50
circle4:setFillColor(0, 0, 0)

displayGroup:insert(circle4)

background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
end)[/lua] [import]uid: 12482 topic_id: 10292 reply_id: 37557[/import]

@hgvyas123

Thank you!

I see that you also re-layout the circles after an orientation change. I knew I had to do that, but what I could not understand is why not doing it would interfere with the positioning of the various backgrounds. That’s what seemed strange to me. (I expected the circles to end up in various incorrect positions, but I didn’t expect the backgrounds to be affected at all.)

I made another package that shows an equally weird behavior:

http://dl.dropbox.com/u/29886031/OrientationMadness2.zip

In this code, I position the top-level group to the center of the screen and I use local coordinates to position the circles within the top-level group.
You will observe that the relative position of the circles remain the same throughout all orientation changes, as expected.

However, it seems the origin of the top-level group becomes the bottom left corner of the screen when the orientation is set to landscape (both landscape right and landscape left).

What do you think?
[import]uid: 59054 topic_id: 10292 reply_id: 37560[/import]

ok as per you said changed the same prev one example see this

[lua]display.setStatusBar(display.HiddenStatusBar)

_W = display.contentWidth;
_H = display.contentHeight;

local displayGroup = display.newGroup()

print("displayGroup.xOrigin = " … displayGroup.xOrigin)
print("displayGroup.yOrigin = " … displayGroup.yOrigin)
print("displayGroup.xReference = " … displayGroup.xReference)
print("displayGroup.yReference = " … displayGroup.yReference)

local background = display.newImageRect(“portrait.png”, 320, 480)
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2

displayGroup:insert(background)

Runtime:addEventListener(“orientation”, function(event)
print("Orientation changed to: " … event.type)
print("event.delta = " … event.delta)

if event.type == “portrait” then
background:removeSelf()

background = display.newImageRect(“portrait.png”, 320, 480)
displayGroup:insert(background)

background:toBack()
elseif event.type == “portraitUpsideDown” then
background:removeSelf()

background = display.newImageRect(“portraitUpsideDown.png”, 320, 480)
displayGroup:insert(background)

background:toBack()
elseif event.type == “landscapeRight” then
background:removeSelf()

background = display.newImageRect(“landscapeRight.png”, 480, 320)
displayGroup:insert(background)

background:toBack()
elseif event.type == “landscapeLeft” then

background:removeSelf()

background = display.newImageRect(“landscapeLeft.png”, 480, 320)
displayGroup:insert(background)

background:toBack()
end
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
end)

local circle1 = display.newCircle(50, 50, 30)
circle1.x = 50
circle1.y = 50
circle1:setFillColor(0, 255, 255)

displayGroup:insert(circle1)

local circle2 = display.newCircle(50, 50, 30)
circle2.x = display.contentWidth - 50
circle2.y = 50
circle2:setFillColor(255, 0, 255)

displayGroup:insert(circle2)

local circle3 = display.newCircle(50, displayGroup.height - 50, 30)

circle3:setFillColor(255, 255, 0)

displayGroup:insert(circle3)

local circle4 = display.newCircle(displayGroup.width - 50, displayGroup.height - 50, 30)

circle4:setFillColor(0, 0, 0)

displayGroup:insert(circle4)[/lua] [import]uid: 12482 topic_id: 10292 reply_id: 37565[/import]

OK, so, basically, the behavior changes in some incoherent fashion depending on the order of coordinate assignments.

It doesn’t make much sense to me.

One thing is sure, I must stop anything else I am doing until I find a rational explanation for what is happening in those sample programs.
[import]uid: 59054 topic_id: 10292 reply_id: 37576[/import]

Alright, so, there was a problem in my code due to Lua closures. Taking a global snapshot of display.contentHeight and display.contentWidth is a bad idea when you plan to support orientation changes because your globals won’t be updated when orientation changes.

The other key thing to understand is that when auto-rotation happens, none of the coordinates of your objects are updated and the old coordinates won’t make sense in the new orientation.
So, you have to re-layout your objects and adjust their coordinates after each orientation change.

Project updated: http://dl.dropbox.com/u/29886031/OrientationMadness3.zip

I don’t think it’s a bug anymore, but it’s a gotcha the documentation should cover. [import]uid: 59054 topic_id: 10292 reply_id: 37662[/import]

nice one :slight_smile: [import]uid: 12482 topic_id: 10292 reply_id: 37752[/import]