Another puzzle or a bug?

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

[lua]local stage
local stageEventShield

local topGroup = display.newGroup();

local function setUpShield()

stage = {
x = 0,
y = 0,
width = display.contentWidth,
height = display.contentHeight
}

stage.left = stage.x
stage.right = stage.x + stage.width
stage.top = stage.y
stage.bottom = stage.y + stage.height

– Create stage event shield

stageEventShield = display.newRect(topGroup,
stage.x, stage.y,
stage.width, stage.height)

stageEventShield.isVisible = false

stageEventShield:setFillColor(255, 255, 255, 128)

– Block all events
stageEventShield:addEventListener(“touch”, function(event)

if event.phase == “ended” then
stageEventShield.isVisible = false

stageEventShield:toBack()
end

return true
end)
end

setUpShield()

Runtime:addEventListener(“orientation”, function(event)

setUpShield()
end)

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

local function raiseShield(event)

if event.phase == “ended” then
stageEventShield.isVisible = true

stageEventShield:toFront()
end
end

background:addEventListener(“touch”, raiseShield)

topGroup:insert(background)

background.x = display.contentWidth / 2
background.y = display.contentHeight / 2[/lua]

Very very simple code, right?

Click once, the shield overlay comes up. Click on the shield overlay, the shield overlay is removed from view.

Now, change orientation to landscape and do the same test.

Notice that the shield overlay doesn’t cover the whole screen.

Why? [import]uid: 59054 topic_id: 10389 reply_id: 310389[/import]

Updated package with some printing for debugging:

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

Very mysterious.

Click once, the shield overlay comes up. Click on the shield overlay, the shield overlay is removed from view.

Now, change orientation to landscape and do the same test.

Notice that the shield overlay doesn’t cover the whole screen. [import]uid: 59054 topic_id: 10389 reply_id: 37869[/import]

I filed a bug for this. No one could find a rational explanation for the behavior. [import]uid: 59054 topic_id: 10389 reply_id: 37925[/import]

Am I somehow over-simplifying this by asking why you use the “orientation” eventListener code to display the shield? Why is this necessary? I didn’t run the code but it appears the shield can be displayed normally, not via any kind of event listener.

Just to confirm… and please correct me if I’m wrong… this “shield” covers the entire screen. It is either “on” or “off”, and it is used to prevent event listeners UNDER the shield when the shield is on (as in, it blocks other touch events). When the shield is clicked, it gets pushed to the back so all other touches are active again.

If this is the case, why not just make the shield a giant square with coordinates 0,0? Say you’re running on iPhone4, just make this shield 1200,1200 in size. It will bleed off the edge of the screen, but it won’t matter, it will cover the entire screen under all device orientations. Then no rotation or orientation code will be necessary.

Brent Sorrentino
Ignis Design

P.S. if you use the above method, you’ll need to explicitly set the coordinate reference point of the giant square to “center” using object:setReferencePoint(display.CenterReferencePoint). This is because the “display.newRect” API defaults to top-left, extending the rectangle right and down to your specified size. You need to reset it to center reference point and then set its coords to 0,0 which should center it in the screen.
[import]uid: 9747 topic_id: 10389 reply_id: 37944[/import]

Thanks for the feedback, Brent.

The code I posted is a test case. I made it to show a problem I am having in a more realistic project I am coding.

Run the test. It’s easy, everything is in the ZIP file. It should take less than 5 minutes.

I do not doubt I will come up with various tricks to avoid the problem, but I wanted to put it out there so that others could try it and confirm that it is in fact a bug that needs to be fixed.

As far as I am concerned, any bug related to the coordinate system used to position display objects is a critical bug. Not because this test case makes any sense, it really doesn’t, but because if this simple test doesn’t work as intended, there is no telling how this bug might hurt you in other more practical and reasonable scenarios.
[import]uid: 59054 topic_id: 10389 reply_id: 37946[/import]

Hi Cerberus,

I think I found the issue. It’s not a “bug” per se. I think you just didn’t properly define (or didn’t create at all) the “build.settings” file for your project. Yes or no? This file is a poorly-documented and widely misunderstood feature of Corona which I hope they remedy soon, i.e. update their documentation and make it very clear to all users how to use it.

Here’s a sample. Save it as “build.settings” in your main project directory:

settings =  
{  
 orientation =  
 {  
 default = "portrait",  
 supported = { "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown" }  
 },  
  
 iphone =  
 {  
 plist =  
 {  
 UIAppFonts =  
 {  
 "arial.otf" , "arial bd.otf"  
 }  
 }  
 }  
}  

Now run the test. The shield should align properly to the left-top under all orientations. The background will rotate too (incorrectly now) but you can handle that by using an orientation listener to display a different background depending on whether it’s landscape or portrait. I think other developers use that tactic quite often.

Does this help? I hope so… :slight_smile:

Brent
[import]uid: 9747 topic_id: 10389 reply_id: 37953[/import]

Thanks, Brent, I’ll give this a try later today.

If that is the case, the documentation will need to be updated.

Thanks so much for your help!
[import]uid: 59054 topic_id: 10389 reply_id: 37957[/import]