2

if touchlocation for zoom is near the corners, black background shown and not zoomed to correct location i want. i want to zoom to touch location but not showing black background. staying with borders

i think it is better to explain with code and screen shots.

note:tileMap size is 800x480 so i scale it to 480x320..

- (id) init {

    if( (self=[super init]) ) {


    self.scaleY=0.66f;
    self.scaleX=0.6f;
    self.anchorPoint = ccp(0,0);
....
}

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

CGPoint touchLocation = [recognizer locationInView:[[CCDirector sharedDirector]view] ];

if(!isGameFinished){
    if(zoomPerformed == NO ) {

        id zoomIn = [CCScaleTo actionWithDuration:0.3f scale:1];
        id sequence = [CCSequence actions:zoomIn, nil];
        [self runAction:sequence ];


        CGSize winSize = [[CCDirector sharedDirector] winSize];
        CGPoint center = ccpMult(ccpFromSize(winSize),0.5);
        center.x = center.x / ((800/480)/0.666f);
        center.y = center.y / 0.666f;
        CGPoint zoomPoint =ccpSub(center,touchLocation);
        zoomPoint = [self myBoundaries:zoomPoint];
        zoomPoint.y = -1 * zoomPoint.y;

        [self runAction:[CCMoveBy actionWithDuration:0.3f position:zoomPoint]];
        zoomPerformed = YES;

        self.anchorPoint = ccp(0,0);

    }else{
    zoomPerformed = NO;
        id moveto = [CCMoveTo actionWithDuration:0.3f position:ccp(0,0)];
        id zoomIn = [CCScaleTo actionWithDuration:0.3f scaleX:0.6 scaleY:0.666];
        id sequence = [CCSequence actions:moveto,zoomIn, nil];
        [self runAction:sequence];
        self.anchorPoint = ccp(0,0);


    }
}
}

-(CGPoint)myBoundaries:(CGPoint)distanceToCenter{
CGSize tileSize = self.tileMap.boundingBox.size;    
CGPoint moveBySize = ccpMult(distanceToCenter,(tileSize.width/tileSize.height));
moveBySize.x = (moveBySize.x*0.6f);
moveBySize.y = (moveBySize.y*0.666f) ;
return moveBySize;
}

before zoom

after zooming to top left corner

4

0 回答 0