cocos2d-iphoneccaction

Cocos2d wave action similar to CCJump


I need to create a wave effect combined with the CCMove action. The CCJump action is very close to what I need but of course without the jumping so its smooth moving up and down until the sprite gets to its end x and y position. Below is the calculation for the CCJump action. Can anyone help me to adapt this code to remove the jumping and allow a smooth flow. Any pointers would be greatly appreciated.

-(void) update: (ccTime) t
{
    // parabolic jump (since v0.8.2)
    ccTime frac = fmodf( t * waves_, 1.0f );
    ccTime y = height_ * 4 * frac * (1 - frac);
    y += delta_.y * t;
    ccTime x = delta_.x * t;
    [target_ setPosition: ccp( startPosition_.x + x, startPosition_.y + y )];
}

Solution

  • I've managed to get a wave effect while the sprite is moving along an X and Y position. The below calculations were taking from the CCWaves class with some slight modification. If anyone knows if this can be improved then please say. To implement this effect I created a new class called CCWaveMove which is a sub class of CCActionInterval.

    -(void) update: (ccTime) t
    {
        ccTime y = (delta_.y + (sinf(t*(CGFloat)M_PI*waves_) * height_ * 1.0f));
        ccTime x = delta_.x * t;
        [target_ setPosition: ccp( startPosition_.x + x, startPosition_.y + y )];        
    }