0

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 )];
}
Peter
  • 749
  • 10
  • 27

2 Answers2

0

Use CCWave for wave action.

id waveAction  = [CCWaves actionWithWaves:5 amplitude:20 horizontal:NO vertical:YES grid:ccg(15,10) duration:20];
id repeate     = [CCRepeatForever actionWithAction:waveAction];
[sprite runAction:repeate];
Guru
  • 21,652
  • 10
  • 63
  • 102
  • Hi Raj, thanks for the post, much appreciated, but its not what I am looking for. the CCWaves action will give the actual sprite a wave effect. I need the sprite to move on a wave without effecting the sprite. This is why I mentioned the CCJump action as this is very close but I don't want the jump effect just need it to be a smooth flow when moving up and down to a given X and Y position. – Peter Jul 24 '12 at 09:58
0

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 )];        
}
Peter
  • 749
  • 10
  • 27