2011-03-18 84 views
1

我想用没有运气,用触摸拖动,以精确的曲线方式移动精灵位置。到目前为止,我使用下面的代码,没有运气曲线雪碧运动COCOS2D

-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event 
{ 
lastTouchLocation = [MultiLayer locationFromTouch:touch]; 
return YES; 
} 

-(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event 
{ 
CGPoint currentTouchLocation = [MultiLayer locationFromTouch:touch]; 
moveTo = ccpSub(lastTouchLocation, currentTouchLocation); 
lastTouchLocation = currentTouchLocation; 
} 

-(void) update:(ccTime)delta 
{  
CCSprite* sprite = [sprites objectAtIndex:1]; 
if (moveTo.x != 0){ 
    float X = sprite.position.x + moveTo.x; 
    float Y = sprite.position.y + (pow(X,2)); 
    sprite.position = CGPointMake(X, Y); 
} 
} 

我试图模拟的曲线方式是在形式y = x^2。这是可行的吗? 在此先感谢!

+0

同样问题与我。我的眼睛在回答。 – 2011-12-06 05:36:25

回答

1

是的,这是可能的。您可以在尝试时手动执行此操作,但最好使用内置解决方案。在cocos2d引擎中有一个CCJumpTo和CCJumpBy操作。它们是为抛物线移动而创建的。使用它们