Я пытаюсь сделать турель, которая поворачивается к месту, которого коснулись, а затем стреляет пулей. Пока нет проблем, но я не мог понять, почему турель не смотрит в сторону, которую я коснулся. ПРИМЕЧАНИЕ: я забыл сказать, что он поворачивается, но не в конкретное место, которого я коснулся. Я просмотрел эти источники, но они не помогли http://www.cocos2d-iphone.org/forum/topic/1823 http://stackoverflow.com/questions/3018688/rotating-and-moving-a-uiimageview-cocoatouch
вот мой код, который делает вращение. Что мне не хватает?
-(void)update:(UITapGestureRecognizer *)recognizer
{
double dx,dy;
CGPoint location = [recognizer locationInView:self.view];
turret.transform=CGAffineTransformIdentity;
bullet.transform=CGAffineTransformIdentity;
bullet.center=turret.center;
if ( location.x < 160 )
{
dx=turret.center.x-location.x;
dy=turret.center.y-location.y;
//if user touched greater than 180
}
else if ( location.x > 160 )
{
dx=location.x-turret.center.x;
dy=location.y-turret.center.y;
//if user touched less than 180
}
CGAffineTransform transform = CGAffineTransformMakeRotation((atan2(dy,dx)*180/M_PI));
NSLog(@"%f",atan2(dy,dx)*180/M_PI);
bullet.transform=transform;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
turret.transform = transform;
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
bullet.center=location;
[UIView commitAnimations];