Disabling touchEnd when pressing buttons - touch

I have a game which is controlled through swipe gestures.
Each turn, the user swipes and it moves pieces on the screen.
My problem is, when pressing the "Start" button, the game starts and sometimes records the first swipe gesture at the same time.
How do I disable the touch messages when I am pressing a button?

You can add a touchEnd handler to the Start button:
on touchEnd
end touchEnd
As long as you don't have a pass touchEnd command in this handler, the touchEnd handler higher up de message hierarchy won't run.
Another possibility is to check for the target higher up the message hierarchy:
on touchEnd
if the short name of the target is "Start" then
exit touchEnd
else
// remainder of your script
end if
end touchEnd

Related

Swift - execute touch up inside if dragged

I have a UIButton which has a function for TouchUpInside. The problem I have is that when the user drags away from the button I would like to cancel the button from functioning, until of course the user presses the button again.
The function that's called when they drag away which is what I'm most likely going to use is TouchDragExit. Can anyone suggest anything in this case?
To elaborate more on what I mean, if the user is holding the button and decides to drag away then drag back to the button I don't want my touchUpInside function to function.
Register an action for the button's UIControl.Event.touchDragExit. When the button fires .touchDragExit, call the button's cancelTracking(with:), passing the UIEvent that it passed to your .touchDragExit action.

Get notification when user pauses dragging

is there a way to get notified when user stops dragging over the screen (using GestureDetector) when the finger is still on the screen? After lifting the finger I do get DragEndDetails event. What I need is sort of "user paused scrolling". Current behaviour is: while moving the finger I do get DragUpdateDetails but when I stop dragging (finger on the screen, drag velocity is 0) neither DragUpdateDetails nor DragEndDetails are fired.
Cheers.
You could just setup a timer (e.g. 1 second) when you receive a drag update event.
If no drag update occurs during that time (or only minimal drag occurs), trigger your callback. Otherwise, if there is significant movement, restart the timer...
When the drag is cancelled or the finger is removed or the widget is disposed, cancel the timer.

How to cancel UITapGestureRecognizer?

I noticed that the single tap happens when the touch dragging is performed quickly.
I want to cancel the single tap if the user moves the touch.
How can I do this?
I noticed that the single tap happens when the touch dragging is performed quickly.
My suggestion is to do nothing. Assuming you have everything set up properly then what you are going to end up doing is creating an app specific behavior for dragging simply to accommodate your personal preference. This could confuse your customers and possibly prevent your app from getting approved.
If the problem you are experience cannot be duplicated in other apps then I would guess that you are doing something incorrectly with respect to the responder chain, and you should focus on fixing that first.
I'm going to assume that you don't want to cancel the tap gesture itself (once the tap gesture has fired, I don't think you can cancel the gesture, it's already done!), but rather the code fired from it.
What you could do is create a timer, and delay the action created by the tap gesture by a second or two. You then have that time interval to cancel the action.

ccTouchesMoved and selector:#selector(ButtonTapped:)

Ill try and keep this as simple as possible.
I have a guy which you drag around the screen
I have a shoot button which fires bullets
To drag the guy around the screen im using ccTouchesMoved, basically get the users finger movement and set the guy to that place. Done.
I have a button which is a CCMenuItemImage and if it is tapped then is called a selector to run a method. The method simply fires some bullets. Done.
Now my problem is i cant have these two things work at the same time. I would like the player to be able to drag around the guy and shoot at the same time. Im assuming the button is not being tapped becuase the user is touching and dragging around the player.
How can i fix this? Still be able to drag around with one finger and press the shoot button with the other and they both work together?
You might want to implement your fire button using a sprite. You can handle ccTouchesBegan and ccTouchesEnded to check for a press within the bounds of your button, to swap it with a pressed state (on begin) or to implement the fire action (on end).
In your ccTouchesMoved handler, you can iterate over the set of touches and determine if the touch that moved is the one over the button, or the touch that should change the character position.

UIButton subclass continuously highlighted after an popping up and UIAlertView

I am subclassing a UIButton and detecting finger movements, if the user swipes his finger in a certain way I will pop up an UIAlerView.
All good, except that after dismissing the UIAlertView... when the user next touches the UIButton the button goes to it's highlighted state and gets stuck there, continuously highlighted, even when no finger touching it.
Pressing the button again the UIButton begins to behave normally (only highlights when touched).
So I can only presume that an alert during a swipe, screws up the process of events, the touchesEnded never firing perhaps?
If anyone has any ideas on how to 'reset' the button after the swipe so that it behaves as it should, I would be grateful.
Are you resetting your state in touchesCancelled?