ここで私がしたこと(それは私にかなりのグーグルを要しました)
実装ファイル内
-(id)init
{
self = [super init];
self.isTouchEnabled=YES;
if (self != nil)
{
}
return self;
}
//pinch recognising
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allUserTouches=[event allTouches];
if(allUserTouches.count==2)
{
UITouch* touch1=[[allUserTouches allObjects] objectAtIndex:0];
UITouch* touch2=[[allUserTouches allObjects] objectAtIndex:1];
CGPoint touch1location=[touch1 locationInView:[touch1 view]];
CGPoint touch2location=[touch2 locationInView:[touch2 view]];
touch1location=[[CCDirector sharedDirector] convertToGL:touch1location];
touch2location=[[CCDirector sharedDirector] convertToGL:touch2location];
ball.position=touch1location;
newBall.position=touch2location;
float currentdist=ccpDistance(touch1location, touch2location);
oldDist=currentdist;
}
}
-(void)ccTouchesMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
NSSet *allUserTouches=[event allTouches];
if(allUserTouches.count==2)
{
UITouch* touch1=[[allUserTouches allObjects] objectAtIndex:0];
UITouch* touch2=[[allUserTouches allObjects] objectAtIndex:1];
CGPoint touch1location=[touch1 locationInView:[touch1 view]];
CGPoint touch2location=[touch2 locationInView:[touch2 view]];
touch1location=[[CCDirector sharedDirector] convertToGL:touch1location];
touch2location=[[CCDirector sharedDirector] convertToGL:touch2location];
float currentdist=ccpDistance(touch1location, touch2location);
if (oldDist>=currentdist)
{
//[spriteToZoom setScale:spriteToZoom.scale-fabs((oldDist-currentdist)/100)];
[ball setPosition:touch1location];
[newBall setPosition:touch2location];
NSLog(@"pinch out");
}
else
{
//[spriteToZoom setScale:spriteToZoom.scale+fabs((oldDist-currentdist)/100)];
[ball setPosition:touch1location];
[newBall setPosition:touch2location];
NSLog(@"pinch in");
}
}
}