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。這是可行的嗎? 在此先感謝!
同樣問題與我。我的眼睛在回答。 – 2011-12-06 05:36:25