just thinking my events are being fired 2 times !!
Upon user tap, I am validating the answer and dispatching a custom event, but not sure why these tap events fire up 2 times. Or there is some parameter I am missing to set it up.
Events fire up 2 times!!
(8 posts) (2 voices)-
Posted 1 year ago #
-
You might be accidentally responding to both TouchesBegan and TouchesEnded. Make sure you included a check on the SPTouch object to ensure you only respond to the desired type.
cheers,
AlexPosted 1 year ago # -
Hey thanks Alex,
my code just does this,
[self addEventListener:@selector(onOptionSelect:) atObject:self forType:SP_EVENT_TYPE_TOUCH];I waas going through the docs, but could not get where to check the TouchesBegan and TouchesEnded events. A sample code will help a lot.
saumya
Posted 1 year ago # -
There are some useful examples here:
http://www.sparrow-framework.org/help/documentation/#eventsincluding one on how to check the event phase from within your event handler using SPTouchEvent touchesWithTarget: andPhase:
Here's an example that checks for the event phase 'touches began'
- (void)onTouch:(SPTouchEvent*)event { SPTouch *touch = [[event touchesWithTarget:self andPhase:SPTouchPhaseBegan] anyObject]; if (touch) { SPPoint *touchPosition = [touch locationInSpace:self]; NSLog(@"Touched position (%f, %f)", touchPosition.x, touchPosition.y); } }Posted 1 year ago # -
oops!
Sorry for my panic. I got it Alex, thank you so very much.
Th trick is in the handler and yes, there is doc in the Sparrow documentation regarding that.NSArray *touches = [[event touchesWithTarget:self andPhase:SPTouchPhaseBegan] allObjects];
if (touches.count==1) {
NSLog(@"One fingure touching!-------");
}Cheers,
saumyaPosted 1 year ago # -
it works but I do not get the last parameter, anyObject/allObjects ?
whats the difference?Posted 1 year ago # -
touchesWithTarget returns an NSSet which is a group of objects, in order to support multitouch. so anyObject is a method of NSSet that returns 'anyObject' from the set (ie a single object, in this case an SPTouch instance).
allObjects is another method ofNSSet that returns an array containing all the objects in the set. Unless you are building a multitouch feature I would expect that you could normally just use the 'anyObject' method.Alex
Posted 1 year ago # -
Thank you Alex. Can not say more
cheesPosted 1 year ago #
Reply
You must log in to post.