Reputation: 11
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 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);
}
}
The curve way i'm trying to simulate is in the form y=x^2. Is this posible? Thanks in advance!
Upvotes: 1
Views: 1887
Reputation: 24846
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
Upvotes: 1