How do I make a touch event only fire when clicking down? Right now it fires when pressing and then it fires again when releasing. Any ideas?
Touch Event
(8 posts) (2 voices)-
Posted 9 months ago #
-
The event will always fire when a touch occurs, but you can then have a look at which "TouchPhase" the touch is in. That way, you can react to, say, only a touch-up event (TouchPhaseEnded).
Here's a sample:
http://wiki.sparrow-framework.org/manual/event_handling#touch_eventsPosted 9 months ago # -
even using TouchPhaseEnded fires twice.
Here is some of the code.
[self addEventListener:@selector(onTouchEvent:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; -(void)onTouchEvent:(SPTouchEvent*)event { NSArray *touches = [[event touchesWithTarget:self andPhase:SPTouchPhaseEnded] allObjects];
Posted 9 months ago # -
Are you absolutely sure this fires twice? Add a breakpoint to the line where you add the event listener, perhaps it's done twice?
Posted 9 months ago # -
I checked that. It only runs that line once. I am at a total loss. I have a textfield on the screen to count clicks and when I click down it adds 1 then when I release it adds another 1. I have no idea what to do.
Posted 9 months ago # -
Wait a moment, I think you misunderstood something here. Check the following code:
[self addEventListener:@selector(onTouchEvent:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; -(void)onTouchEvent:(SPTouchEvent*)event { NSArray *touch = [[event touchesWithTarget:self andPhase:SPTouchPhaseEnded] anyObject]; if (touch) { NSLog(@"a touch ended"); } }
So you've got to put youre code inside the "if (touch)" part. The event fires multiple times, but it will enter the if-clause only when the user removes the finger from the screen.
Posted 9 months ago # -
Oh my gosh, thanks! I can't believe I didn't catch that myself.
Posted 9 months ago # -
You're welcome! =)
I know this part is a little tricky, because it's different to how it's done in Flash. But it works fine once you're used to it!
Posted 9 months ago #
Reply
You must log in to post.