2011-03-18 83 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操作。它們是爲拋物線移動而創建的。使用它們