Another puzzle or a bug?

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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

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.

I filed a bug for this. No one could find a rational explanation for the behavior.

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.

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.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
settings =
{
        orientation =
        {
                default = "portrait",
                supported = { "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown" }
        },
        
        iphone =
        {
                plist =
                {
                        UIAppFonts =
                        {
                                "arial.otf" , "arial bd.otf"
                        }
                }
        }
}

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!

views:1900 update:2011/9/30 9:15:39
corona forums © 2003-2011