Я пытаюсь сделать револьверную головку, которая поворачивается к месту, к которому прикоснулся, а затем стреляет в пулю. Пока проблем нет, но я не мог понять, почему турель не смотрит в ту сторону, к которой я прикоснулся. ПРИМЕЧАНИЕ: я забылсказать, что он поворачивается, но не в конкретное место, которое я коснулся.Я посмотрел на эти источники, но они не помогли http://www.cocos2d -iphone.org / forum / topic / 1823 /2633577/vraschenie-i-peremeschenie-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];