Applying Zoom Effect In cocos2D gaming environment?

后端 未结 4 1394
抹茶落季
抹茶落季 2021-01-30 11:39

I\'m working on a game with cocos2D game engine and make load all the sprites while it load the level, now as because some of sprites (obs

4条回答
  •  抹茶落季
    2021-01-30 12:10

    My code and it works better than other ones:

    - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
        NSArray* allTouches = [[event allTouches] allObjects];
        CCLayer *gameField = (CCLayer *)[self getChildByTag:TAG_GAMEFIELD];
        if (allTouches.count == 2) {
    
            UIView *v = [[CCDirector sharedDirector] view];
            UITouch *tOne = [allTouches objectAtIndex:0];
            UITouch *tTwo = [allTouches objectAtIndex:1];
            CGPoint firstTouch = [tOne locationInView:v];
            CGPoint secondTouch = [tTwo locationInView:v];
            CGPoint oldFirstTouch = [tOne previousLocationInView:v];
            CGPoint oldSecondTouch = [tTwo previousLocationInView:v];
            float oldPinchDistance = ccpDistance(oldFirstTouch, oldSecondTouch);
            float newPinchDistance = ccpDistance(firstTouch, secondTouch);
    
            float distanceDelta = newPinchDistance - oldPinchDistance;
            NSLog(@"%f", distanceDelta);
            CGPoint pinchCenter = ccpMidpoint(firstTouch, secondTouch);
            pinchCenter = [gameField convertToNodeSpace:pinchCenter];
    
            gameField.scale = gameField.scale - distanceDelta / 100;
            if (gameField.scale < 0) {
    
                gameField.scale = 0;
            }
        }
    }
    

提交回复
热议问题