我似乎在计算精灵和触摸点之间的角度时遇到了问题。每当用户触摸屏幕时,我试图让我的精灵直接面对触摸点的方向。这是我的代码:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint tapPosition;
for (UITouch *touch in touches){
CGPoint location = [touch locationInView:[touch view]];
tapPosition = [self convertToNodeSpace:[[CCDirector sharedDirector] convertToGL:location]];
}
float angle = CC_RADIANS_TO_DEGREES(ccpAngle(fish.position, tapPosition));
[fish runAction:[CCRotateTo actionWithDuration:0.5 angle:angle]];
}
有任何想法吗?谢谢