Ios 如何在cocos2d中更改缩放中心?

Ios 如何在cocos2d中更改缩放中心?,ios,cocos2d-iphone,uigesturerecognizer,Ios,Cocos2d Iphone,Uigesturerecognizer,我想缩放到触摸位置,但此代码总是缩放到屏幕中心 -(id)init{ UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector(handleDoubleTapFrom:)]; doubleTap.numberOfTapsRequired = 2; doubleTap.numberOfTouchesRequired = 1;

我想缩放到触摸位置,但此代码总是缩放到屏幕中心

-(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;
        }
    }
}

如何更改缩放原点?我搜索了一下,但没有一种方法奏效

您需要移动正在缩放(缩放)的图层,以便触摸位置对应的点位于屏幕的中心

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

缩小时,您还需要重置图层的位置。

经过一些修改后,它对我有效。我用moveBy将moveTo更改为,并采用ccpSub()的相反方向。y,CGPoint zoomPoint=ccpSub(中心,触摸位置);[自运行操作:[CCMoveBy操作,持续时间:1.0f位置:ccp(zoomPoint.x,-zoomPoint.y)];