Hi,
i have a problem again with the SPTouchEvent ...
i have a SPSprite Class and want to get the TouchEvent for this SPSprite, and I am doing the following.
- (id)init {
...
[self addEventListener:@selector(onTouchLevel01:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
...
}
-(void)onTouchLevel01:(SPTouchEvent *)event{
SPDisplayObject* currentObject = (SPDisplayObject*)[event target];
NSArray *touches = [[event touchesWithTarget:self andPhase:SPTouchPhaseMoved] allObjects];
if (touches.count == 1)
{
SPTouch *touch = [touches objectAtIndex:0];
SPPoint *currentPos = [touch locationInSpace:self.parent];
SPPoint *previousPos = [touch previousLocationInSpace:self.parent];
NSLog(@"Level01:onTouchLevel01 ! 1x touches -> x: %d y: %d", (int)currentPos.x, (int)currentPos.y);
}else if (touches.count == 2) {
SPTouch *touch = [touches objectAtIndex:0];
SPPoint *currentPos = [touch locationInSpace:self.parent];
SPPoint *previousPos = [touch previousLocationInSpace:self.parent];
NSLog(@"Level01:onTouchLevel01 ! 2x touches -> x: %d y: %d", (int)currentPos.x, (int)currentPos.y);
}else if (touches.count >2) {
SPTouch *touch = [touches objectAtIndex:0];
SPPoint *previousPos = [touch previousLocationInSpace:self.parent];
SPPoint *currentPos = [touch locationInSpace:self.parent];
NSLog(@"Level01:onTouchLevel01 ! Xx touches -> x: %d y: %d", (int)currentPos.x, (int)currentPos.y);
}else {
NSLog(@"Touches Array empty!");
}So it compiles, the EventHandler is called after touching the SPSprite-Class (containing a background-image). BUT touches count is ZERO after a tap! When i slide the finger over the display the touch count is ONE! And i get the correct values for a tap.
Why does this happen, that only a slid is recognized and not a tap!? but the function is called after tapping!!
Any ideas to get the coordinates of the touch properly!
Thank you so much in advance!!
christian