0

我有以下代码:

- (void)panning:(UIPanGestureRecognizer *)recognizer {

CGPoint position;
//CGPoint velocity;
//velocity = [recognizer velocityInView:[CCDirector sharedDirector].view];

switch( recognizer.state ) {
    case UIGestureRecognizerStatePossible:
        break;

    case UIGestureRecognizerStateBegan:
    {
        position = [recognizer locationInView:[CCDirector sharedDirector].view];

        for (CCSprite *sprite in movableSprites) {
            if (CGRectContainsPoint(sprite.boundingBox, position)) {
                selSprite = sprite;
                break;
            }
        }
        break;
    }
    case UIGestureRecognizerStateChanged:
    {
        position = [recognizer locationInView:[CCDirector sharedDirector].view];
        CGPoint yInvertedPosition = CGPointMake(position.x, -position.y);
        [selSprite setPosition:position];
        break;
    }
    case UIGestureRecognizerStateFailed:
        break;

    case UIGestureRecognizerStateEnded:
        break;

    case UIGestureRecognizerStateCancelled:
        break;
}

}

当我拖动一个精灵时,它在 X 轴上移动正常,但它在 Y 轴上倒置。

我怎样才能转换它?

 CGPoint yInvertedPosition = CGPointMake(position.x, -position.y);

这不起作用

4

1 回答 1

0

您只需要将您的位置转换为 GL 坐标。

case UIGestureRecognizerStateBegan:
{
    position = [recognizer locationInView:[CCDirector sharedDirector].view];
    position = [[CCDirector sharedDirector] convertToGL:position];

    for (CCSprite *sprite in movableSprites) {
        if (CGRectContainsPoint(sprite.boundingBox, position)) {
            selSprite = sprite;
            break;
        }
    }
    break;
}
case UIGestureRecognizerStateChanged:
{
    position = [recognizer locationInView:[CCDirector sharedDirector].view];
    position = [[CCDirector sharedDirector] convertToGL:position];
    [selSprite setPosition:position];
    break;
}
于 2013-03-13T03:42:09.360 回答