Forked from horatio-sans-serif/CCLayerPanZoomTestLayer.m
          
        
    
          Created
          July 31, 2014 15:43 
        
      - 
      
- 
        Save xiangyuan/86acb8981d8563e910dc to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | - (void) layerPanZoom: (CCLayerPanZoom *) sender | |
| clickedAtPoint: (CGPoint) point | |
| tapCount: (NSUInteger) tapCount | |
| { | |
| NSLog(@"CCLayerPanZoomTestLayer#layerPanZoom: %@ clickedAtPoint: { %f, %f }", sender, point.x, point.y); | |
| if (tapCount == 2) { | |
| // Toggle zooming all the way in and all the way out. | |
| float midScale = (sender.minScale + sender.maxScale) / 2.0; | |
| float newScale = (sender.scale <= midScale) ? sender.maxScale : sender.minScale; | |
| // Zoom towards the tap point. Note that scaling is performed "around" the anchor point. | |
| // Thus, we need to account for how far the layer should be translated after its scaling | |
| // change is performed. | |
| CGPoint anchorPointNodeSpace = ccp(sender.anchorPoint.x * sender.contentSize.width, | |
| sender.anchorPoint.y * sender.contentSize.height); | |
| CGFloat deltaScale = newScale - sender.scale; | |
| CGPoint deltaPos = ccpMult(ccpSub(point, anchorPointNodeSpace), deltaScale); | |
| // Scale and translate in parallel. We negate the direction since to zoom to the point | |
| // we want to move the layer in the opposite direction. | |
| [sender runAction:[CCSpawn actions: | |
| [CCScaleTo actionWithDuration:0.4 scale:newScale], | |
| [CCMoveBy actionWithDuration:0.4 position:ccpNeg(deltaPos)], | |
| nil]]; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment