임 게임을 만들기가있는 UIImageView에 (공) 무작위로 아이폰 화면의 가장자리 주위에 반사. 사용자는 볼을 구멍/타겟 안으로 유도하기 위해 손가락으로 라인을 그려야합니다. 나는 무작위로 튀는 공과 스크린에 그릴 수있는 능력을 구현할 수 있었다. 내 문제는 내가 볼 때 볼과 사용자가 그린 선 사이에 충돌이 생겼다는 것입니다. 공이 그냥 통과합니다. 나는 CGRectIntersectsRect를 사용하려했지만이 방법은 효과가 없다고 확신한다. 내가 기본적으로 원하는 것은 사용자가 그려진 선에서 튀어 오르는 공을 얻는 방법입니다. 누구든지이 작업을 수행하는 방법에 대한 아이디어가 있고 도움이된다면 매우 감사 할 것입니다. 사전엑스 코드 - 사용자 그려 줄 충돌 감지
필자의
덕분에 시도하고 너희들이 내 셋업이 무엇인지 이해하는 데 도움이되는 몇 가지 코드를 추가했다. 손가락이
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
fingerSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 0;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
// sets the width of the line
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
//sets the colour of the line drawn
//red
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
//green
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0);
//blue
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 1.0, 1.0);
//black
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
//draws a line to the point where the user has touched the screen
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
fingerMoved++;
}
가 Heres는 내가 현재에 노력하고있어 화면을 가로 질러 이동할 때
터치는 사용자가 처음 화면에 자신의 손가락을두고 어디
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
fingerSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self.view];
startPoint = [touch locationInView:self.view];
lastPoint.y -= 0;
}
터치가 이동되어 시작 실제 충돌 감지에 사용 ...
float a = lastPoint.y - startPoint.y;
float b = startPoint.x - lastPoint.x;
float c = lastPoint.x * startPoint.y - startPoint.x * lastPoint.y;
float d = abs(a * ball.center.x + b *ball.center.y + c)/sqrtf(powf(a,2)+ powf(b,2));
if(d ==0){
NSLog(@"collision detected");
}
이 갈 매우 가능한 방법처럼 보이지만 또 다른 문제는 사용자 (플레이어) 단지 그림의 응용 프로그램처럼 자신의 손가락으로 여러 선을 그릴해야한다는 것이 이들 라인은 고체 물체의 일종 역할을 것이다에 공이 튀어 나올 수 있습니다. 그러므로 당신이 제안한 방식대로하면 아마 1 줄이면 좋겠지 만 많은 경우 지저분해질 수 있습니다. 스틱의 끝이 틀린 것이 아니라면 ... – Tossy12