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 回答