我正在尝试根据屏幕上的滑动方向移动精灵。到目前为止,这是我根据互联网上的示例提出的代码:
-(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 度之间滑动时执行操作,而不是通过侧向或向下滑动。我该如何实施?