2013-04-05 54 views

回答

0

這裏就是一個例子。這將我的mapNode帶回到左邊界,例如當LHS菜單彈出時。移動持續時間和加速度計算爲期望位移的函數:

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

    } 

} 
+0

這看起來非常像我已經嘗試過的。只要增加序列的易用性 - 有一個例外;速率參數。如果未指定費率,那麼緩解不起作用(只是跳到結束價值)。如果指定費率(我將它設置爲1),它就可以工作。 – Jonny 2013-04-05 04:57:28