开发者

Curve Sprite Movement COCOS2D

I'm trying with no luck to move a sprite position in an simetric curve way with the touch drag. So far I use the following code with no luck

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

-(void) ccTouchMoved:(UITouch*)touch with开发者_StackOverflow社区Event:(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);
}
}

The curve way i'm trying to simulate is in the form y=x^2. Is this posible? Thanks in advance!


Yes it's possible. You can do it manually as your are trying, but it's better to use a built-in solution. There is a CCJumpTo and CCJumpBy actions in cocos2d engine. They are created for parabolic moves. Use them

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜