我正试着用触摸拖动以simetric曲线的方式移动精灵位置。到目前为止,我使用以下代码没有运气
-(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 :(得分:1)
是的,这是可能的。您可以在尝试时手动执行此操作,但最好使用内置解决方案。在cocos2d引擎中有一个CCJumpTo和CCJumpBy动作。它们是为抛物线移动而创建的。使用它们