views:

45

answers:

1

Hi,

I am working on Cocos2D 0.9.3 version. I am making a demo game called DoodleJump. now when I am making an object to jump on Touch event , It will jump to the next level.

I have statically defined Jump height like this.

actionTo = [CCJumpTo actionWithDuration:1 position:ccp(SpriteImage.position.x,40+28) height:110 jumps:1]; [SpriteImage runAction: actionTo];

It will jump correctly on platform at level 1 . but when it will land on platform at level 2 , it will jump not its full height but will jump very low compared to previous jump. on level 3 it will jump lower than level 2 and so on. It will gradually decreasing in height in jumping.

Please help .

A: 

I think you need to change this:

ccp(SpriteImage.position.x,40+28)

to this:

ccp(SpriteImage.position.x, SpriteImage.position.y + 40 + 28)

Overall I did not really understand how CCJump works, it's very confusing and I had issues with slightly jumping too high or low over time. I ended up using my own jump code using velocity. This is done in an update method and kGravity is a constant (0.2f):

velocity.y -= kGravity;
self.position = CGPointMake(position_.x += velocity.x, position_.y += velocity.y);

When you want to jump, you simply set velocity.y to a higher value, like 10. And if the player falls too fast, so simply make sure velocity.y goes past some tweakable value like -20.

GamingHorror