Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with tap and swipe. How should I optimize? #80

Open
BeauKelsey opened this issue Jan 11, 2015 · 3 comments
Open

Issues with tap and swipe. How should I optimize? #80

BeauKelsey opened this issue Jan 11, 2015 · 3 comments

Comments

@BeauKelsey
Copy link

Hello!
I am working on a game where there is a hero. The hero can jump with swipe up on the stage and he can fire with tap on the stage. Things get a little wonky and weird when I try and do some rapid fire and quick jumping. How can I optimize this to work better? Should be adding eventListeners with separate methods?

Here the code... any help MUCH appreciated.

tap.addEventListener(GestureEvent.GESTURE_STATE_CHANGE, onGesture);
swipe.addEventListener(GestureEvent.GESTURE_STATE_CHANGE, onGesture);



private function onGesture(event:GestureEvent):void
        {
            trace(event.target+ event.newState.toString());

            if(event.target == tap){
                if(event.type == "gestureRecognized"){
                    bulletManager.fire();
                }
            }else if(event.target == swipe){
                if(event.type == "gestureRecognized"){
                    heroJump(event);
                    swipe.removeEventListener(GestureEvent.GESTURE_RECOGNIZED, onGesture);
                }else if(event.type == "gestureIdle"){
                    swipe.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onGesture);
                }
            }
        }
@fljot
Copy link
Owner

fljot commented Jan 11, 2015

@BeauKelsey dude I wish I could help you, but your problem description is "a little wonky and weird"... add some logs, analyze what is unexpected-undesired.

@BeauKelsey
Copy link
Author

The code above works. However, when I tap on the screen and swipe up rapidly around at the same time... both gestures fail. See the below trace:

[object TapGesture]GestureState.POSSIBLE
[object SwipeGesture]GestureState.POSSIBLE
[object TapGesture]GestureState.FAILED
[object SwipeGesture]GestureState.FAILED
[object SwipeGesture]GestureState.IDLE
[object TapGesture]GestureState.IDLE

How Can I optimize my gestures so that firing(tap) and jumping(swipe) are happening seamlessly.
Is it best practices to fire the same method for both gestures and use if statements to decide which gesture it is? To put it another way... I only have a fraction of a second to figure out if it's a tap or a swipe.
Is my example above the best way to do that?

@fljot
Copy link
Owner

fljot commented Jan 15, 2015

@BeauKelsey first thing I'd recommend you is to understand why each fails. Add some extra logging (get the stack trace) when state is changing to FAILED.
There's absolutely no connection between your event handlers and "fraction of a second" thing.. I don't even get it, why do you have that question arisen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants