0

タッチ位置にズームしたいのですが、このコードは常に画面の中央にズームします。

-(id)init{
 UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector(handleDoubleTapFrom:)];
    doubleTap.numberOfTapsRequired = 2;
    doubleTap.numberOfTouchesRequired = 1;
    [[[CCDirector sharedDirector] view] addGestureRecognizer:doubleTap];
}

- (void)handleDoubleTapFrom:(UITapGestureRecognizer *)recognizer {

    //CGPoint touchLocation = [recognizer locationInView:[[CCDirector sharedDirector]view] ];
    if(!isGameFinished){
        if(zoomPerformed == NO ) {
            id zoomIn = [CCScaleTo actionWithDuration:1.0f scale:2];
            id sequence = [CCSequence actions:zoomIn, nil];
            [self runAction:sequence];
            zoomPerformed = YES;
        }else{
            id zoomOut = [CCScaleTo actionWithDuration:1.0f scale:1.0f];
            id sequence = [CCSequence actions:zoomOut, nil];
            [self runAction:sequence];
            zoomPerformed = NO;
        }
    }
}

ズームの原点を変更するにはどうすればよいですか? 私は検索しましたが、どの方法もうまくいきませんでした。

4

1 に答える 1

0

タッチ位置に対応するポイントが画面の中央になるように、スケーリング (ズーム) されているレイヤーを移動する必要があります。

CGSize winSize = [[CCDirector sharedDirector] winSize];
CGPoint center = ccpMult(ccpFromSize(winSize), 0.5);
[self runAction:[CCMoveTo actionWithDuration:1.0f position:ccpSub(center, touchLocation)]];

また、ズームアウトするときにレイヤーの位置をリセットする必要があります。

于 2013-01-10T13:20:35.240 に答える