Hi guys, i need your help. i have a game concept in my mind where i can move 2 sprites in any direction i want with 2 fingers.(move sprite both at same time, something like iphone ice hockey game).
I have a code which i can move the sprite with single touch. What changes i need to make i so i can move it correctly with two fingers?
.
CCSprite *icon;
CCSprite *eye;
.
.
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView: [myTouch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
CGRect IconSpriteRect = CGRectMake(icon.position.x - (icon.contentSize.width/2),
icon.position.y - (icon.contentSize.height/2),icon.contentSize.width,
icon.contentSize.height);
if (CGRectContainsPoint(IconSpriteRect, location)) {
iconTouch=TRUE;
}
CGRect faceSpriteRect = CGRectMake(eyes.position.x - (eyes.contentSize.width/2),
eyes.position.y - (eyes.contentSize.height/2),
eyes.contentSize.width,
eyes.contentSize.height);
if (CGRectContainsPoint(faceSpriteRect, location)) {
eyesTouch=TRUE;
}
}
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:[myTouch view]];
point = [[CCDirector sharedDirector] convertToGL:point];
if(iconTouch==TRUE){
[icon setPosition:ccp(icon.position.x, point.y)];
}
if(eyesTouch==TRUE){
[eyes setPosition:point];
}
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
iconTouch=FALSE;
eyesTouch=FALSE;
}