-1

我想使用该touchesMoved方法在屏幕上旋转图像。因此,如果我将手指从右侧移动到左侧,我希望我的图像从左到右旋转。

这有可能吗?

4

1 回答 1

0

找到了解决方案!

- (void)handleDragFrom:(CGPoint)start to:(CGPoint)end
{
    [super handleDragFrom:start to:end];

    float rotationCenterX = self.player.position.x - (self.player.contentSize.width / 2);
    float rotationCenterY = self.player.position.y - (self.player.contentSize.height / 2);

    float dXStart = start.x - rotationCenterX;
    float dYStart = start.y - rotationCenterY;
    float radianStart = atan2(dYStart, dXStart);

    float dXEnd = end.x - rotationCenterX;
    float dYEnd = end.y - rotationCenterY;
    float radianEnd = atan2(dYEnd, dXEnd);

    float radian = GLKMathRadiansToDegrees(radianEnd - radianStart);

    self.player.rotation -= radian;
}

“开始”和“结束”是从触摸移动给出的两个点:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    CGPoint end = [touch locationInView:self.view];
    CGPoint start = [touch previousLocationInView:self.view];

    [self.scene handleDragFrom:start to:end];
}
于 2013-03-30T06:13:17.023 回答