если вы хотите найти угол пролистывания, вы должны использовать здесь тригонометрию ..
Вот некоторые из них, которые могут вам помочь.
- ( void ) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
locationTouchBegan = [touch locationInView: [touch view]];
//location is The Point Where The User Touched
locationTouchBegan = [[CCDirector sharedDirector] convertToGL:locationTouchBegan];
//Detect the Touch On Ball
if(CGRectContainsPoint([ball boundingBox], locationTouchBegan))
{
isBallTouched=YES;
}
}
это то, как вы обнаруживаете, что мяч коснулся
Теперь на сенсорном конце мы можем вычислить направление.
- ( void ) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
locationTouchEnded = [touch locationInView: [touch view]];
locationTouchEnded = [[CCDirector sharedDirector] convertToGL:locationTouchEnded];
[self calculateDirections];
}
так мы вычисляем направление.
-(void)calculateDirections
{
if (isBallTouched==YES )
{
perpendicularBig = screenSize.height - ball.position.x;
baseSmall = screenSize.width/2 - locationTouchEnded.x; // if the ball is at center.
perpendicularSmall=locationTouchEnded.y - ball.position.x;
baseBig=(perpendicularBig*baseSmall)/perpendicularSmall;
endPoint=ccp(screenSize.width/2 - baseBig,320); //320 can replace by the value of end point y where you want to end the ball run.
[self moveBall:3.0f];
}
}
-(void)moveBall:(float)duration
{
[ball runAction:[CCJumpTo actionWithDuration:duration position:ccp(endPoint.x,endPoint.y) height:20 jumps:1]];
isBallTouched = NO;
}