CCEaseBounce rate change

CCEaseBounce rate change
0.0 0



Is it possible to control the bouncing rate of an object, which bounces by following code:

tab->runAction(CCEaseBounceOut::create(CCMoveBy::create(1.0, ccp(0,c->screenHeight*0.25))));

Is it possible to alter the rate of bouncing? If yes, someone please tell me how?

I peaked through the CCActionEase.cpp and tried understanding bounceTime(), but its too cryptic for me.




What do you mean by “rate of bouncing” ? Would you like your ball to bounce for 10 seconds doing 10 “bounces”? If so, you already have code for a second-long bounce, all you’ve got to do is put it in a separate function and schedule it as a selector.

For example :

void bouncyBall() {
    //code to bounce the ball one time

//Somewhere in your corresponding init method/class constructor:
schedule(schedule_selector(YourClassName::bouncyBall), <#float interval#>, <#unsigned int repeat#>, <#float delay#>));
//The rest of the parameters should be self-explanatory.


Thanks for the reply Pawel :slight_smile:

By `rate of bounce`, I mean the intensity level of the bouncing. The default bounce effect is too strong for me, I want to make a lighter bounce with a reduced number of bounces happening. By default, CCEaseBounceOut and CCEaseBounceOut makes the sprite bounce 4 or 5 times. Need to reduce it to 2.

I believe something should be done with CCEaseBounce::bounceTime, but I quite dont understand whats happening in that function


Well, maybe you could try to experiment with it like that :

CCEaseBounceOut *bounce = CCEaseBounceOut::create(CCMoveBy::create(1.0, ccp(0,c->screenHeight*0.25)));
bounce->setBounceTime(/*put different values here to check results*/);



bounceTime is being called from action’s update function… so calling it once, after the action is created dont have any effect.


I ended up writing a custom Bounce class, with only changes to the bounceTime() as follows:

float CCArenaBounce::bounceTime(float time) {
if (time < 2 / 2.75) {
CCLog(“time < 1 / 2.75 f", 1.9 * time * time);
return 1.9 * time * time;
} else if(time < 2.5 / 2.75) {
time -= 2.25f / 2.75f;
CCLog("time < 2.5 / 2.75 f”, 7.5625f * time * time + 0.9375f);
return 7.5625f * time * time + 0.9375f;
time -= 2.625f / 2.75f;
CCLog(“time < 2.75 %f”, 7.5625f * time * time + 0.984375f);
return 7.5625f * time * time + 0.984375f;