Issues with tap and swipe. How should I optimize?
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);
}
}
}
@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.
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?
@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?