1つのオブジェクトとユーザーが触れた場所の間に線を引こうとしています。サブクラス化を試しましたが、ユーザーが画面に触れるたびに「-(void)drawrect」を更新することができません。これらのファイルを削除して、コードを「-(void)touchesbegan」に正しく配置しようとしましたが、機能しません。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
CGPoint locationOfTouch = [touch locationInView:nil];
// You can now use locationOfTouch.x and locationOfTouch.y as the user's coordinates
Int xpos = (int)(starShip.center.x);
int ypos = (int)(starShip.center.y);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), starShip.center.x, starShip.center.y);
//draws a line to the point where the user has touched the screen
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), locationOfTouch.x, locationOfTouch.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
}