안녕하세요,저기서 위치를 돌리려고 터렛을 만들려고 노력하고 있습니다. thats는 건드리지 만 총알을 쏘습니다. 지금까지 문제가 없었지만 왜 포탑인지 알 수 없었습니다. does not는 i가 만지는 방향을 만난다 주 : 나는 그것이 만졌던 특별한 위치에 그것이 회전한다라고 말하는 것을 잊었다. 나는이 소스를 보았다 그러나 그들은 http://stackoverflow.com/questions/3018688/rotating-and-moving-a-uiimageview-cocoatouchUIImageVíew에 각도 회전 만들기 그러나 그것은 무엇을 기대하게 만들지 않습니다.
http://www.cocos2d-iphone.org/forum/topic/1823 여기에 회전을 수행 내 코드가 도움이 didnt한다. 나는 무엇을 놓치고 있습니까? 내가 CGAffineTransformMakeRotation 사용하는 생각
-(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];
실제로 무엇을합니까? 전혀 회전합니까, 그렇다면 어떤 방식으로 회전합니까? – jrtc27