Gamua / Sparrow-Framework

The Open Source Game Engine for iOS
http://www.sparrow-framework.org
Other
294 stars 83 forks source link

When screen changes orientation an old touch never finishes and a new touch never begins #11

Closed ArielLorenzo-Luaces closed 11 years ago

ArielLorenzo-Luaces commented 11 years ago

This problem became apparent after implementing an object's behavior which depended on touches ending. Apparently when the screen changes orientation the old touch is never sent to the touched object with an SPTouchPhaseEnded phase. In fact, the object stops receiving any touch messages at all (even with SPTouchPhaseMoved phase) exactly at the point when the screen is flipped.

Is this a known issue?

PrimaryFeather commented 11 years ago

Hm, I'm hearing this for the first time! But it's not unlikely that this causes a problem. May I ask on which device you encountered this -- Android or iOS?

PrimaryFeather commented 11 years ago

I just tried it on both, and it works for me -- but I just remembered that I fixed a similar issue (aborted touches) a while ago, probably after v1.3. I guess you're using Starling 1.3?

ArielLorenzo-Luaces commented 11 years ago

I'm using Sparrow 2.0 06b0d6b156ae4740c70691930660a106fda5f2d7 on an iPad3

Testing was done by using the following code:

    for (SPTouch *touch in [touchEvent touchesWithTarget:self])
    {
        if (touch.phase == SPTouchPhaseBegan)
        {
            NSLog(@"touch.phase == SPTouchPhaseBegan");
        }
        else if (touch.phase == SPTouchPhaseMoved)
        {
            NSLog(@"touch.phase == SPTouchPhaseMoved");
        }
        else if (touch.phase == SPTouchPhaseStationary)
        {
            NSLog(@"touch.phase == SPTouchPhaseStationary");
        }
        else if (touch.phase == SPTouchPhaseEnded)
        {
            NSLog(@"touch.phase == SPTouchPhaseEnded");
        }
        else if (touch.phase == SPTouchPhaseCancelled)
        {
            NSLog(@"touch.phase == SPTouchPhaseCancelled");
        }
    }

When the iPad is flipped and the orientation changes then the finger is lifted, the last message recieved is "touch.phase == SPTouchPhaseMoved"

Actually I just realized that if after the orientation changes and the finger is still within the area of the object being touched, it will falsely behave as if the touch is uninterrupted and you will get the SPTouchPhaseEnded message. I say falsely because it happens as a coincidence of the new touch being captured by the same object.

PrimaryFeather commented 11 years ago

Oh my ... sorry, I actually didn't check that we were talking about Sparrow! I made my tests with Starling yesterday ... LOL, that happens when you multitask too much ...! ;-)

I'll look into that and get back to you soon.

PrimaryFeather commented 11 years ago

Please try again! Now it should work. Thanks for the report, BTW! =)

ArielLorenzo-Luaces commented 11 years ago

Well I was about to say that I was experiencing the same behavior. But I looked deeper into the problem and into your changes. Apparently a new SPTouch was being created every time no matter what, and the reason was because "existingTouch" always had a nil "nativeTouch". So I added the moving of the native touch pointer from touch to the current "new" touch in SPTouchProcessor. 109209411c6211c516ad1b7267c0a6c9f3fa2ddb

Now everything works as expected and touches are ended when the finger is released even after a change in orientation.

Np for the report. I find it strange that it hasn't caused a problem for anyone else, lol. =)

PrimaryFeather commented 11 years ago

Wait a minute -- you say that it didn't work for you? I tested it on both my iPhone and iPad, and it worked just fine. Could you tell me how exactly to reproduce your problem?

BTW, you can't just push to this repository -- I'm quite baffled that this change went through! You'd need to send me a pull request so I can merge such a change.

Don't worry about, though -- I can do it manually, it's not much code. But before, I need to understand what is going on.

PrimaryFeather commented 11 years ago

Hm, ok, I think I see what's going on. Weird that it worked in my tests ... I'll get back to you soon.

ArielLorenzo-Luaces commented 11 years ago

wait what. I didn't push to this repository I'm confused too

PrimaryFeather commented 11 years ago

Hm, I've never seen that before! Look here: https://github.com/Gamua/Sparrow-Framework/commit/109209411c6211c516ad1b7267c0a6c9f3fa2ddb

ArielLorenzo-Luaces commented 11 years ago

Oh, I pasted that hash from my upstream here https://github.com/arielsw/Sparrow-Framework/commits/master

PrimaryFeather commented 11 years ago

Ah! Odd that GitHub displays this as belonging to "Gamua/Sparrow-Framework" (when you look at the other link). ;-)

ArielLorenzo-Luaces commented 11 years ago

oh wow, this is crazy. github is showing my changes on my upstream as changes that happened in Gamua

ArielLorenzo-Luaces commented 11 years ago

LOL that's a funny bug github has there. you can pretty much do it with any other person https://github.com/Shilo/Sparrow-Framework/commit/109209411c6211c516ad1b7267c0a6c9f3fa2ddb https://github.com/Gamua/Sparrow-Framework/commit/109209411c6211c516ad1b7267c0a6c9f3fa2ddb https://github.com/PrimaryFeather/Sparrow-Framework/commit/109209411c6211c516ad1b7267c0a6c9f3fa2ddb

PrimaryFeather commented 11 years ago

LOL! An interesting find! ;-)

In any case, you're totally right about my last commit. That was bullsh*t, I must have been sitting on my eyes ...

PrimaryFeather commented 11 years ago

Please try it again, now it should really work.

I don't know why I previously always created a new touch event at that point. I'm now simply reusing the object that's passed into the method.

ArielLorenzo-Luaces commented 11 years ago

Yup, works perfectly thumbs up

PrimaryFeather commented 11 years ago

I'm glad to hear that! Thanks for the update.