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 に答える