0
votes

after applying to a Box2D body:

    b2Vec2 force = b2Vec2(velocity.x/PTM_RATIO, velocity.y/PTM_RATIO); 
   _body->ApplyLinearImpulse(force,_body->GetPosition());

I'm trying as in many game (like doodle jump) to stop moving the hero body once it reaches a certain distance from the top of the screen and start scrolling the stage so that we feel the hero is still climbing higher. For this I need to move the hero in the first place and then move the stage.

How can this be achieved correctly ? Any idea?

1

1 Answers

0
votes

Thats quite an odd thinking to solve the problem. You never stop the character or any of the environment objects. Let them behave as they are intended by box2d. You have everything added to one root node of some sort, your environment and the character. What you do is create some sort of a "camera controller" and you give the characters CCSprite, or the wrapping objects if you have one, as a target. In the update function that you call each frame you change the root nodes position in a way that it centres the screen on the character. You can implement follow delays, smooth scrolling and other nice features as you need them.

Unfortunately I don't use Cocos2d at all, so I can't give you a sample code. The given solution will work for Cocos2d as it is not far of the engine I use at my work place.