Long Delay before touch is seen ...

I have a moderately complex program in development, a version of the old SpaceWar program. It seems to have an odd behavior.

There are controls on the screen for each player, circles for left turn, right turn, power, fire. The game completes initialization with elapsed time about 0.05 seconds.

Sometimes, when i press the Left button, the game does not respond. I put a print of touch id, state, coords, and elapsed in, and start the game and press the button and hold. The first occurrence of a touch occurs maybe 6 seconds in (sometimes 4.5). But it doesn’t always happen, and right now, after just adding some prints, it’s not happening at all.

Ideas on what could make a thing like that happen?

iPad Pro, if that matters, the new .2 version, though it was happening on the .1 as well.

Ideas welcome! Thanks!

I wonder if you had the check for BEGAN or MOVING for your button if that would have caught it.

EDIT: Never mind. I tried just using BEGAN and touched() recognized the BEGAN event when I slid my finger from off screen onto the screen.

EDIT: I just tried something else and that might be the answer. If you just have BEGAN as the event for your button and your button is close to the edge then as you slide your finger from off screen to on screen, the BEGAN event will happen but its not in the button area. When it slides into the button area, then it’s MOVING and not BEGAN.

It’s hard to know without seeing code. That isn’t a problem I’ve heard of before.

Can you test on an older iPad to eliminate the Pro as a problem?

Is it just the left button, or any touch?

Is the program doing any work in draw that could cause delays?

(But I guess I should know better than to suppose you wouldn’t have tried all this already).

If you write a simple program that just tests button presses, do you have a problem with that. If not, something is interfering with the touched function. Or maybe the button area isn’t as large as you think it is and you’re not touching the correct spot.

Yes, when putting in print statements doesn’t help, I often create a minimal test program like Dave suggested, or else comment out big chunks of the program until I isolate the problem. But it’s difficult to debug such visual programs, and I often get stuck for hours.

yes. i am quite sure (without having checked)) that a test program will show everything fine. i think it’s been happening right along, even on the old iPad – which would be hard to test on the same version, though i assume there’s some way to move the code.

my intuitive reaction is that it only happens on this one button (on my side of the screen (i don’t usually use the far side buttons when testing).

i’m assuming something is interfering (or was, since it seems not to be happening) … only thing i can think of that would interfere would be getting stuck in a draw event with a long loop (or a long loop in the touch event, which is less likely). I had thought it might be a long program init but that was measurably not the case.

so looking for crazy ideas that will make me go Aha! because otherwise i’m in for some digging … :slight_smile:

Thanks!

if it’s definitely only one button (ie the others work without delays) then I would try moving the button to the right and see if it still delays, which I expect it will, but it’s worth confirming that fact.

If it’s just one button, and has nothing to do with its placement, then surely it comes back to what that bitton does when pressed.

My current guess is that the button is very close to the left edge and if you touch outside the screen and then drag in, you do not get a touch event (ever, as far as i can tell).

i think i need to adjust where the buttons are and how they are going to work.

Hi Dave,

Yes, that could certainly explain some of the behavior I’ve seen. My recollection, though, is that I have put my finger straight down on the button and held it, and the first touch event happened 4-6 seconds ElapsedTime. I can’t duplicate it at the moment, and all I changed was to put in some prints. Very odd.

That said, I do need to figure out better what I want to have happen when people’s fingers slide in and out. I’m inclined to have the control “capture” that id when a touch is seen inside (and the control doesn’t have a captured id), and lose the touch when the touch is lifted … and maybe when it slides back out.

I’m not finding BEGAN, MOVING, ENDED to be as handy as they might be but they certainly allow one more than enough flexibility. :slight_smile:

Thanks,

Dave … and it seems I’m not seeing a touch event EVER when i slide from offscreen and hold. Seem to get no event until I lift and put back down. I’ll check that further … :slight_smile:

That is definitely not happening in .2 in full screen no buttons when swiping from the round button side on the iPad pro, swiping down low. I can bring stuff in from the RIGHT, Inthink, will check some more.

@RonJeffries Try this. The top button is half way off the top of the screen. On my iPad Air, if I touch each button they turn red (BEGAN). If I slide my finger sideways across each button, they turn green (MOVING). If I slide my finger down from off screen from the top, the top button turns red (BEGAN), then green (MOVING). So even though my finger is MOVING, the top button will report a BEGAN event (red) when it hits the button, then a MOVING event (green).

function setup()
    rectMode(CENTER)    
end

function draw()
    background(0)
    fill(255)
    if b1b then 
        fill(255,0,0)
    end
    if b1m then 
        fill(0,255,0)
    end
    rect(WIDTH/2,HEIGHT,100,100)
    fill(255)
    if b2b then 
        fill(255,0,0)
    end
    if b2m then 
        fill(0,255,0)
    end
    rect(WIDTH/2,HEIGHT-200,100,100)
end

function touched(t)
    b1b,b1m=false,false
    b2b,b2m=false,false
    if t.x>WIDTH/2-50 and t.x<WIDTH/2+50 and t.y>HEIGHT-50 and t.y<HEIGHT+50 then
        if t.state==BEGAN then
            b1b=true
        end
        if t.state==MOVING then
            b1m=true
        end
    end
    if t.x>WIDTH/2-50 and t.x<WIDTH/2+50 and t.y>HEIGHT-250 and t.y<HEIGHT-150 then
        if t.state==BEGAN then
            b2b=true
        end
        if t.state==MOVING then
            b2m=true
        end
    end
end

Fascinating. In landscape mode, round button to left, I see events dragging in from off-screen at top, right, bottom, AND NOT LEFT. I absolutely do not see any touch events from dragging in from the left (round button) side.

if I swipe from the output pane to the right, I don’t register any touch events either.

EDIT: If I swipe from offscreen on the left to the right, the program screen moves right and the editor screen shows which it should. So basically, I can’t swipe from offscreen left to the right without closing the program. That’s one way to exit a program when in fullscreen no buttons mode.

Confirmed. iPad pro, landscape, round button on left, I can pull down from top edge and get notifications or whatever those are, and then the codea controls show up. Same pulling from right edge, with the multi tasking panel. Nothing happens pulling from bottom, nothing happens pulling from left side.

On the top and right ones, I get that little < handle and must pull it, quickly, or it just goes away and the program keeps going.

Preview of probable bug report:

I’ve written a simple Main that watches for touches, changes background color, and displays x and y at screen center. I’m on my Mac now so can’t post it yet.

Near the lower left corner (Round button on left, have not tried other rotations), a touch very close to the left or bottom edge is simply not seen at all. Distances < 10 pixels, roughly. These are seen on the other edges or out toward the middle of the bottom. Only happens in lower left corner. (That is, near 0,0)

I’ve not tried on my iPad Air or whatever it is, but my current guess at the problem is that the screen coordinate transformation for the iPad Pro is involved, since the Pro’s screen seems to be limited to 2048 virtual points, not the machine’s actual pixel dimensions. So my guess is that it’s going to work correctly on an ordinary iPad and not work on the Pro, and that the problem is in the rounding/truncating involved in converting the touch event, deep inside Codea.

Another possibility is that the device really isn’t generating a touch but I doubt that.

Anyone else out there got a Pro?