Draggable cards (touch enumeration) issue
- by glitch
I'm trying to let a player tap, drag and release a card from a fanned stack on the screen to a 4x4 field on the board. My cards are instantiated from a custom class that inherits from the UIImageView class.
I started with the Touches sample app, and I modified the event handlers for touches to iterate over my player's card hand instead of the 3 squares the sample app allows you to move on screen. Everything works, until that is, I move the card I'm dragging near another card. I'm really drawing a blank here for the logic to get the cards to behave properly. Here's my code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSUInteger numTaps = [[touches anyObject] tapCount];
if(numTaps = 1) {
for (UITouch *touch in touches) {
[self dispatchFirstTouchAtPoint:[touch locationInView: self.boardCardView] forEvent:nil];
}
}
}
-(void) dispatchFirstTouchAtPoint:(CGPoint)touchPoint forEvent:(UIEvent *)event
{
for (int i = 0; i<5; i++)
{
UIImageView *touchedCard = boardBuffer[i];
if (CGRectContainsPoint([touchedCard frame], touchPoint)) {
[self animateFirstTouchAtPoint:touchPoint forView:touchedCard];
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSUInteger touchCount = 0;
for (UITouch *touch in touches){
[self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.boardCardView]];
touchCount++;
}
}
My questions are:
How do I get the touch logic to disallow other cards from being picked up by a dragging finger?
Is there anyway I can only enumerate the objects that are directly below a player's finger and explicitly disable other objects from responding?
Thanks!