Search code examples
cocos2d-iphonesequenceeasing

CCEaseIn etc inside CCSequence


How do you exactly use easing inside CCSequence?

Related to Using CCEaseOut together with CCSequence?


Solution

  • here is an example. This brings back my mapNode to the left border, for example when a LHS menu is popped out. Move duration and acceleration are computed as a function of the expected displacement :

    - (void)setLeftClamp:(float)leftClamp {
    
        _leftClamp = leftClamp;
    
        CGPoint currentPosition = self.mapNode.position;
        if (currentPosition.x > self.maxX) {
            // ease right back in position
            CGPoint delta         = ccp (self.maxX - currentPosition.x, 0);
            id      move          = [CCMoveBy actionWithDuration:[self moveDuration:delta] position:delta];
            id      ease          = [CCEaseIn actionWithAction:move rate:[self moveAcceleration:delta]];
            id      delay         = [CCDelayTime actionWithDuration:.1f];
            id      easeAndCenter = [CCSequence actions:ease, delay, [CCCallFunc actionWithTarget:self selector:@selector(onMoveComplete)], nil];
            [self.mapNode runAction:easeAndCenter];
    
            targetMapLocation_ = ccpAdd(self.mapNode.position, delta);
            mapDisplacement_   = delta;
            isMapMoving_       = YES;
    
        }
    
    }