画面のスワイプ方向に応じてスプライトを動かそうとしています。これまでのところ、これはインターネット上の例に基づいて私が思いついたコードです。
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
endTouch = location;
float swipeLength = endTouch.x - beginTouch.x;
float swipeY = endTouch.y - beginTouch.y;
if(swipeY > 0)
{
if(swipeLength == 0){
//Do action here
}}}
さて、私の質問は、endTouch.xの範囲を制限する必要があるということです。たとえば、100より大きく150未満である必要があります。横または下にスワイプするのではなく、上向きまたは50〜120度などの特定の角度でスワイプした場合にのみアクションを実行します。どうすればこれを実装できますか?