# cocos2d ccTouchEnded: Removing a Touch

These are my ccTouch__ methods. Note that I am using the singular form of the functions (ie. ccTouchBegan v. ccTouchesBegan (don't know if that has anything to do with it, but it can't hurt to point it out)).

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
//NSLog(@"1");

CGPoint touchLocation = [GameScene locationFromTouch:touch];
CTouch* newTouch = [[CTouch alloc] initWithStart:touchLocation];

//Right now the UILayer takes all touch events and handles them
return YES;
}

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
//NSLog(@"2");

//Get the touch's location and previous location
CGPoint touchLocation = [GameScene locationFromTouch:touch];
CGPoint lastTouchLocation = [GameScene previousLocationFromTouch:touch];
//Check which CTouch has been moved and move it
for (CTouch* ct in touches){

if ([ct checkSameTouch:lastTouchLocation]) {
[ct setCurrentPosition:touchLocation];
}
}

}

-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
NSLog(@"3");

//Get the touch's location
CGPoint touchLocation = [GameScene locationFromTouch:touch];
CGPoint lastTouchLocation = [GameScene previousLocationFromTouch:touch];
//The CTouch object to be removed
//You can't remove an object from the array while its being enumerated
CTouch* removeTouch;

//Check and hold which CTouch has ended
for (CTouch* ct in touches){

if ([ct checkSameTouch:lastTouchLocation]) {
removeTouch = ct;
}
}

//Remove the touch
[touches removeObject:removeTouch];
}


For some reason, the way I'm checking which CTouch object in touches to move in the ccTouchMoved function works fine, but when I try the exact same thing in ccTouchEnded, it doesn't work.

EDIT: I take it back. The "if" statement to update ct in ccTouchMoved only works the first time. I think this might be the real problem. Because the CTouch object isn't being updated, its information isn't the same as the UITouch object's by the time the touch ends.

I have tried the "if" statement in ccTouchEnded with both the lastTouchLocation and touchLocation and neither of them work. The "if" statement is never true and removeTouch is, therefore, always empty.

The lastTouchLocation and touchLocation in ccTouchEnded are always wildly different from the ct.lastPosition. Just to make sure I cover everything, here's a sample set:

ct.lastPosition:     84,125
ct.currentPosition:  85,125

lastTouchLocation:   155,131
touchLocation:       174,132